Hola
Soy nuevo en el foro y quisiera que me ayudaseis.
Estoy creando una web y nesesito que desde 1 consulta a la base de datos. que ahora tengo 2 consultas:
$consulta1 = "SELECT * FROM x_contenido_web WHERE mod(x_id,2) = 0 ORDER BY `x_id` DESC LIMIT 0,3";
$consulta2 = "SELECT * FROM x_contenido_web WHERE mod(x_id,2)<> 0 ORDER BY `x_id` DESC LIMIT 0,3";
quiero que sea 1 consulta y mostrar luego en 2 tablas diferente informacion.
Este es el codigo que tengo:
<?php
include '_config/config1.php';
if(isset($_GET['pagina']))
{
$page= $_GET['pagina'];
}
else
{
$page=1;
}
$consulta = "SELECT * FROM x_contenido_web ORDER BY `x_id` DESC";
$consulta1 = "SELECT * FROM x_contenido_web WHERE mod(x_id,2) = 0 ORDER BY `x_id` DESC LIMIT 0,3";
$consulta2 = "SELECT * FROM x_contenido_web WHERE mod(x_id,2)<> 0 ORDER BY `x_id` DESC LIMIT 0,3";
$datos=mysql_query($consulta,$CON);
$datos1=mysql_query($consulta1,$CON);
$datos2=mysql_query($consulta2,$CON);
$num_rows=mysql_num_rows($datos);
$rows_per_page= 6;
$lastpage= ceil($num_rows / $rows_per_page);
$page=(int)$page;
if($page > $lastpage)
{
$page= $lastpage;
}
if($page < 1)
{
$page=1;
}
$limit= 'LIMIT '. ($page -1) * $rows_per_page . ',' .$rows_per_page;
$consulta .=" $limit";
$post=mysql_query($consulta,$CON);
if(!$post)
{
die('Invalid query: ' . mysql_error());
}
else
{
?>
<html>
<table width="961" height="710">
<tr>
<td height="645">
<table width="40%" border="0">
<tr>
<td width="43%" height="283" align="right">
<table border="0" cellpadding="0" cellspacing="0">
<?php do { ?>
<tr>
<td>
<table width="100%" border="0" align="center">
<tr>
<td align=left ><a href="post.php?pagina=0&id=<?php echo $datos22['x_id']; ?>"><img src="<?php echo $datos22['x_imagen_article']; ?>" width="310" height="250" /></a></td>
</tr>
<tr>
<td class="es1" align="left"><?php echo $datos22['x_title'];?></td>
</tr>
<tr>
<td class="es2"align="left"><?php echo $datos22['x_text_mini'];?> <a href="post.php?pagina=0&id=<?php echo $datos22['x_id']; ?>">(Leer más..)</a></td>
</tr>
</table>
<br>
</td>
</tr>
<?php } while ($datos22 = mysql_fetch_assoc($datos1)); ?>
</table>
</td>
<td width="57%">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<?php do { ?>
<tr>
<td align="left"><table width="200" border="0" align="center">
<tr>
<td align=left >
<a href="post.php?pagina=0&id=<?php echo $datos11['x_id']; ?>"><img src="<?php echo $datos11['x_imagen_article']; ?>" width="310" height="250" /></a></td>
</tr>
<tr>
<td class="es1" align="left"><?php echo $datos11['x_title'];?></td>
</tr>
<tr>
<td class="es2" align="left"><?php echo $datos11['x_text_mini'];?><a href="post.php?pagina=0&id=<?php echo $datos11['x_id']; ?>"> (Leer más..)</a></td>
</tr>
</table>
<br>
</td>
</tr>
<?php } while ($datos11 = mysql_fetch_assoc($datos2)); ?>
</table></td></tr>
</table>
<br>
<br>
<table width="648">
<tr>
<td width="316" align="center"height="72"><div align="center"> <?php if($num_rows != 0)
{
$nextpage= $page +1;
$prevpage= $page -1;
?><ul id="pagination"><?php
if ($page == 1)
{
?>
<li class="previous-off">« Anterior</li>
<li class="active">1</li>
<?php for($i= $page+1; $i<= $lastpage ; $i++) { ?>
<li><a href="home.php?pagina=<?php echo $i;?>"><?php echo $i;?></a></li>
<?php } if($lastpage >$page ){?>
<li class="next"><a href="home.php?pagina=<?php echo $nextpage;?>" >Siguiente »</a></li><?php }else{?>
<li class="next-off">Siguiente »</li><?php }} else { ?>
<li class="previous"><a href="home.php?pagina=<?php echo $prevpage;?>">« Anterior</a></li><?php
for($i= 1; $i<= $lastpage ; $i++) { if($page == $i) { ?> <li class="active"><?php echo $i;?></li><?php
} else { ?> <li><a href="home.php?pagina=<?php echo $i;?>" ><?php echo $i;?></a></li><?php
}} if($lastpage >$page ){ ?>
<li class="next"><a href="home.php?pagina=<?php echo $nextpage;?>">Siguiente »</a></li><?php
} else { ?> <li class="next-off">Siguiente »</li><?php
}} ?></ul><?php } ?></div></td>
</tr>
</table>
</html>
Como podeis ver me estoy haciendo un lio, nesesito que con 1 consulta se pueda mostrar en 2 tablas 2 informaciones diferentes que serian 2 publicaciones que estan guardadas en la base de daos.
O tener 2 consultas diferentes a la base de datos, pero si ago 2 consultas diferentes cuando muestro la informacion la paginaciion de la web no funciona.
O sino el caso seria alguna solucion de paginacion con 2 consultas porque sino me muestra la misma informacion en las 2 tablas.