Re: Mostrar los resultados de una query myql divididos por paginasnumeradas
| From: | Manuel Gonzalez | Date: | Thu, 20 May 2004 14:34:49 +0000 |
| Subject: | Re: Mostrar los resultados de una query myql divididos por paginasnumeradas | ||
| Groups: | php.general.es | ||
| Request: | Send a blank email to general-es+get-48711@lists.php.net to get a copy of this message | ||
esto esta en el histotial de la lista, si te fijas de ultima te mando lo que tengo implementado,
se puede mejorar pero anda bien
saludos
Manuel González
<?
//Se imprimen todas las noticias con su titulo su foto y la fecha de publicación
while ($line = mysql_fetch_array($result,MYSQL_ASSOC)){
print "<tr>";
list($ano , $mes , $dia) = sscanf($line["TextFch"], "%d- %d- %d-");
print "<td whidth='547' height='30'><img
src='Imagenes/";
print $line["TextPathFoto"];
print "' width='53'
height='33'> <a
href='Ver_Noticias_Ant.php?id=";
print $line["TextCod"];
print "' class='linck2'>";
print $line["TextTit"];
print "</a></td></tr><tr><td width='100%'
height='16' bgcolor='#CCCCCC'>";
print "<font face='Verdana'
size='-2'>Fecha: $dia/$mes/$ano</font></td></tr>";
print "<tr><td height='20'> </td></tr>";
}
//se libera la memoria y se cierra la coneccion con la base
mysql_free_result($result);
$con = mysql_close($con);
//Se imprime el pie para navegar en la paginación de los resultados
print "<tr><td height='30'> </td></tr>";
print "<tr><td width'100%'>";
echo "<p class='texto1'>Páginas de Resultados: ";
if ($pg <> 0){
$url = $pg - 1;
echo "<a
href='Listado_de_Noticias.php?pg=".$url."'><<</a> ";
}
else {
echo " ";
}
for ($i = 0; $i<($pages + 1); $i++) {
if ($i == $pg) {
echo "<font face=Arial size=2 color=ff0000><b> $i </b></font>";
}
else {
echo "<a
href='Listado_de_Noticias.php?pg=".$i."'>".$i."</a> ";
}
}
if ($pg < $pages) {
$url = $pg + 1;
echo "<a
href='Listado_de_Noticias.php?pg=".$url."'>>></a>";
}
else {
echo " ";
}
echo "</p>";
print "</td></tr>";
print "<tr><td height='40'> </td></tr>";
?>
>>> Kpromos <info@kpromos.com> 4:47:31 20/05/2004 >>>
Espero que alguien pueda ayudarme. Tengo una función con un ciclo while que
genera los resultados de una query mysql. Quisiera generar un flujo
automatico de los resultados, con el número de páginas para mostrar todos
los mismos en distintas paginas ... <Previous> 1 2 3 4 <Next>
La función es la siguiente y luego está el escript que debería incorporar
pero no logro hacerlo. ¿Alguien podría ayudarme?:
===== función que muestra los resultados ======
function display($show_what) {
switch ($show_what) {
case "":
$sql = "select * from news2 ORDER BY date DESC, time DESC";
break;
}
display_posts($sql);
}
function display_posts($sql) {
connect();
$result = mysql_query($sql) or die(mysql_error());
?>
<table width="100%" border="0" cellpadding="5"
align="CENTER">
<tr>
<td> <hr align="RIGHT" size="1" width="100%"
noshade> </td>
</tr>
<?
while($row = mysql_fetch_array($result)) {
?> <tr><td> <?
if($last_date == $row["date"]):?>
<p class="date"><b><?echo $row["time"]?></b>
<?else:?>
<p class="date"><?echo $row["time"]?> - <b><?echo
$row["date"]?></b>
<?endif;
$cat_num = $row["category_id"];
$cat_result = mysql_query("select categories.category from news2,
categories where news2.category_id = categories.category_id and
news2.category_id = '$cat_num'");
$cat = mysql_fetch_array($cat_result);
?>
<br>
................
..........
</tr>
<?
}
?>
</table>
<?
}
=== script para generar las paginas ===
$table = 'news2'; // The name of your table in the database
$limit = '2'; // How many results should be shown at a time
$scroll = '10'; // How many elements to the navigation bar are shown at a time
// Get the total number of rows in a database
$query1 = mysql_query ("SELECT * FROM news2");
$numrows = mysql_num_rows ($query1);
//
if (!isset ($_GET[show])) {
$display = 1; // Change to $NUMROWS if DESCENDING order is required
} else {
$display = $_GET[show];
}
// Return results from START to LIMIT
$start = (($display * $limit) - $limit);
$query2 = mysql_query ("SELECT * FROM $table LIMIT $start,$limit");
while ($myrow = mysql_fetch_array ($query2)) {
echo "<p>".$myrow[ROW]."</p>"; // EDIT TO REFLECT YOUR RESULTS
}
//
$paging = ceil ($numrows / $limit);
// Display the navigation
if ($display > 1) {
$previous = $display - 1;
echo "<a href=\"$_SERVER[PHP_SELF]?show=1\"><< First</a> | ";
echo "<a href=\"$_SERVER[PHP_SELF]?show=$previous\">< Previous</a> |
";
}
if ($numrows != $limit) {
if ($paging > $scroll) {
$first = $_GET[show];
$last = ($scroll - 1) + $_GET[show];
} else {
$first = 1;
$last = $paging;
}
if ($last > $paging ) {
$first = $paging - ($scroll - 1);
$last = $paging;
}
for ($i = $first;$i <= $last;$i++){
if ($display == $i) {
echo "<b>$i</b> ";
} else {
echo "<a href=\"$_SERVER[PHP_SELF]?show=$i\">$i</a> ";
}
}
}
if ($display < $paging) {
$next = $display + 1;
echo "| <a href=\"$_SERVER[PHP_SELF]?show=$next\">Next ></a> |
";
echo "<a href=\"$_SERVER[PHP_SELF]?show=$numrows\">Last
>></a>";
}
//
?>
--
PHP Spanish Localization Talk Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php