Page 1 of 1
I need help with pagination.
Posted: Fri Dec 09, 2005 1:35 pm
by Maluendaster
hey all.. I'm still a n00b in this, i have a problem and don't know how to do it, i've been trying to do it since a week and 0 results, can anyone help me? I need to show the :
< Previous - 1 2 3 4 5 .. 10 - Next >
I think i have to insert it in this code (show_gals.php) This file shows all galleries posted in a MySQL Databes
Code: Select all
<?php
include("insertar/conex.php");
$link=Conectarse();
$result=mysql_query("select * from galeria ORDER by ID_Prueba DESC",$link);
?>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 width=100% style="BORDER-RIGHT: #373737 1px solid; BORDER-TOP: #373737 1px solid; BORDER-LEFT: #373737 1px solid; BORDER-BOTTOM: #373737 1px solid">
<?php
while($row = mysql_fetch_array($result)) {
printf("<tr><td bgcolor=373737><center><font face=verdana size=2 color=white><b>%s</b></center></td></tr><tr><td><center><br><img src=%s><br></center><center><a href=out.php?dire=%s target=_blank><br><img src=common/view_gallery.gif></a></center></td></tr>", $row["Nombre"], $row["Imagen"],$row["Url"]);
}
mysql_free_result($result);
mysql_close($link);
?>
Can anyone??? please..
It's for my site, don't know if i can put the url since it's a erotic site....
Thank you.
Posted: Fri Dec 09, 2005 1:57 pm
by Jade
This isn't really that hard to do. The basic concept is this:
Code: Select all
<?php
include("insertar/conex.php");
$link=Conectarse();
$limit = 25;
if (!$page)
$page = 1;
$limitvalue = $page * $limit - ($limit);
$result=mysql_query("select * from galeria ORDER by ID_Prueba DESC LIMIT $limitvalue, $limit",$link);
?>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 width=100% style="BORDER-RIGHT: #373737 1px solid; BORDER-TOP: #373737 1px solid; BORDER-LEFT: #373737 1px solid; BORDER-BOTTOM: #373737 1px solid">
<?php
while($row = mysql_fetch_array($result)) {
printf("<tr><td bgcolor=373737><center><font face=verdana size=2 color=white><b>%s</b></center></td></tr><tr><td><center><br><img src=%s><br></center><center><a href=out.php?dire=%s target=_blank><br><img src=common/view_gallery.gif></a></center></td></tr>", $row["Nombre"], $row["Imagen"],$row["Url"]);
}
if ($page != 1)
{
$pageprev = $page - 1;
echo "<a href=?page=$pageprev><<Previous</a>";
}
$numofpages = round(mysql_num_rows($result) / $limit);
for($i = $page; $i <= $numofpages; $i++)
{
if($i == $page)
echo $i;
else
{
echo "<a href=?page=$i>$i</a>";
if ($i % 15 == 0)
{
echo "...";
$i = $numofpages+1;
}//end if
} //end else
} //end for
if(($count - ($limit * $page)) > 0)
{
$pagenext = $page + 1;
echo "<a href=?page=$pagenext>Next >></a>";
}
mysql_free_result($result);
mysql_close($link);
?>
Posted: Fri Dec 09, 2005 1:59 pm
by Maluendaster
thank you! i'll try that and tell you how it went... you are a nice human...

Posted: Fri Dec 09, 2005 2:00 pm
by Jade
you're welcome. We've all been there before.
Posted: Fri Dec 09, 2005 2:19 pm
by Maluendaster
it woked, but the pagination shows just a 1 , no next or something.... did i do something wrong? , I got the limit at 5 and i have like 40 entries in the db.
Posted: Fri Dec 09, 2005 2:31 pm
by pickle
Do a forum search for pagination. You might find something helpful in the other topics about pagination.
Posted: Fri Dec 09, 2005 11:18 pm
by Maluendaster
I Can't make it work!!!
Jade please, help me.. here's the code....
Code: Select all
<?php
include("insertar/conex.php");
$link=Conectarse();
$limit = 500;
$page = $_GET['page'];
if (!$page)
$page = 1;
$limitvalue = $page * $limit - ($limit);
$result=mysql_query("select * from galeria ORDER by ID_Prueba DESC LIMIT $limitvalue, $limit",$link);
?>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 width=100% style="BORDER-RIGHT: #373737 1px solid; BORDER-TOP: #373737 1px solid; BORDER-LEFT: #373737 1px solid; BORDER-BOTTOM: #373737 1px solid">
<?php
while($row = mysql_fetch_array($result)) {
printf("<tr><td bgcolor=373737><center><font face=verdana size=2 color=white><b>%s</b></center></td></tr><tr><td><center><br><img border=0 src=%s><br></center><center><a href=out.php?dire=%s target=_blank><br><img src=common/view_gallery.gif></a></center></td></tr>", $row["Nombre"], $row["Imagen"],$row["Url"]);
}
if ($page != 1)
{
$pageprev = $page - 1;
echo "<a href=?page=$pageprev>Previous</a>";
}
$numofpages = round(mysql_num_rows($result) / $limit);
for($i = $page; $i <= $numofpages; $i++)
{
if($i == $page)
echo $i;
else
{
echo "<a href=?page=$i>$i</a>";
if ($i % 15 == 0)
{
echo "...";
$i = $numofpages+1;
}//end if
} //end else
} //end for
if(($count - ($limit * $page)) > 0)
{
$pagenext = $page + 1;
echo "<a href=?page=$pagenext>Next</a>";
}
mysql_free_result($result);
mysql_close($link);
?>
Posted: Sat Dec 10, 2005 7:02 am
by shiznatix
viewtopic.php?t=38830
a very good pagentation class. if you cant figure out how to work that then you should really just search this forum for pagentation and you will find many results with answers