Page 1 of 1
More Help - Thanks
Posted: Wed Feb 12, 2003 8:56 pm
by Mr. Tech
Hi again
I also need help on another thing for my links directory.
How do I make it so that if I have 11 links on the page(these are collected from the MySQL Database) the 11th link will be put on another page.
Like on this forum for example, when you have a certain amount of topics they move onto another page called page 2.
Understand?
Thanks
Ben
Posted: Wed Feb 12, 2003 9:54 pm
by volka
perform a
search on all these terms "limit per page" and you will find plenty of threads about this topic here

Posted: Wed Feb 12, 2003 9:57 pm
by Mr. Tech
Thanks! I wasn't sure what to search for!
Posted: Thu Feb 13, 2003 3:03 am
by Mr. Tech
Do you think(If possible) you could point out a specific thread? There are 235 matches!!!
Posted: Thu Feb 13, 2003 3:23 am
by twigletmac
Did you do 'search for all terms'? That should hopefully narrow it down somewhat.
Mac
Posted: Thu Feb 13, 2003 3:30 am
by Mr. Tech
I found this:
It took me a while to work it out for my own script, but this is what I used.
It works by adding page='a number' to the query string.
$rpp = 10; //results per page
$post_start = (($page*$rpp)-($rpp-1)); //work out which row to start with
$prev_page = $page-1; //next page number
$next_page = $page+1; //prev page number
$sql = ("Your normal select statement with this added: id>=$post_start and id<$post_start+$rpp order by post_no");
$numsql = ("Normal select statement getting list of all results");
$numquery = mysql_query( $numsql );
$num_rows = mysql_num_rows( $numquery ); //how many results?
$pages = ceil($num_rows/$rpp); //gives how many pages you will have
//Print your records out as normal
print ("Currently viewing page $page of $pages<br>");
if( $page <= 1 )
{
print ("< Prev [ "); //if page 1, then you can't go to the previous one
}
else
{
print ("<a href=\"$PHP_SELF?page=$prev_page\">< Prev</a> [ "); //go to $page-1
}
for($i=1; $i<=$pages; $i++) //prints list of page numbers
{
if( $i == $page )
{
print ("$i "); //don't want to link to the page your viewing
}
else
{
print ("<a href=\"$PHP_SELF?page=$i\">$i</a> "); //sets up link to page number
}
}
if( $next_page > $pages )
{
print (" ] Next > <p>"); //if on last page, don't allow next page link
}
else
{
print ("] <a href=\"$PHP_SELF?page=$next_page\">Next ></a><p>"); //go to $page+1
}
Will print out something like this:
Currently viewing page 3 of 5.
<prev [ 1 2 3 4 5 ] next>
How could I intergrate that with this:
<?php
if ($searchby == "catid") {
$showresults = "select * from phpbiglinks_cats where (cat rlike '$search') order by cat";
}
else if ($searchby == "cattitle") {
$showresults = "select * from phpbiglinks_cats where (title rlike '$search') order by title";
}
else if ($searchby == "catdescription") {
$showresults = "select * from phpbiglinks_cats where (description rlike '$search') order by description";
}
$showresultsresult = mysql_query($showresults) or die("Failed: $sql");
$numrows = mysql_num_rows($showresultsresult);
$half = intval($numrows / 1);
if (($half+$half)!=$numrows) $half = $half + 1;
print "";
for($x=0;$x<$numrows;$x++) {
$resrow = mysql_fetch_row($showresultsresult);
$cat = $resrow[0];
$subcat = $resrow[1];
$maincat = $resrow[2];
$links = $resrow[3];
$title = $resrow[4];
$description = $resrow[5];
$ctfolder = str_replace(" ", "_", $cat);
if ($x==$half) print "";
print "
<form action=\"cat.php\" method=\"get\">
<tr>
<td class=\"wholebody2\" width=\"50%\">$lang[catid]:</td><td class=\"wholebody2\">$cat</td>
</tr><tr>
<td class=\"wholebody2\">$lang[subcat]:</td><td class=\"wholebody2\">$subcat</td>
</tr><tr>
<td class=\"wholebody2\">$lang[maincat](If a Sub Category):</td><td class=\"wholebody2\">$maincats[title]</td>
</tr><tr>
<td class=\"wholebody2\">$lang[catname]:</td><td class=\"wholebody2\">$title</td>
</tr><tr>
<td class=\"wholebody2\">$lang[catdesc]:</td><td class=\"wholebody2\">$description</td>
</tr><tr>
<td class=\"wholebody2\">$lang[catlinks]:</td><td class=\"wholebody2\">$links</td>
</tr>
<tr>
<td bgcolor=\"white\">
<form action=\"cat.php\" method=\"get\">
<input type=\"hidden\" name=\"file\" value=\"edit\">
<input type=\"hidden\" name=\"mode\" value=\"delete\">
<input type=\"hidden\" name=\"cat\" value=\"$cat\">
<input type=\"hidden\" name=\"subcat\" value=\"$subcat\">
<input type=\"hidden\" name=\"maincat\" value=\"$maincats[title]\">
<input type=\"hidden\" name=\"title\" value=\"$title\">
<input type=\"hidden\" name=\"description\" value=\"$description\">
<input type=\"hidden\" name=\"links\" value=\"$links\">
<input type=\"submit\" value=\"$lang[deleteabove]\">
</form>
</td>
<td bgcolor=\"white\" align=\"right\">
<form action=\"cat.php\" method=\"get\">
<input type=\"hidden\" name=\"file\" value=\"edit\">
<input type=\"hidden\" name=\"mode\" value=\"edit\">
<input type=\"hidden\" name=\"editcat\" value=\"$cat\">
<input type=\"submit\" value=\"$lang[editabove]\">
</form>
</td>
</tr>
";
}
print "\n</table>";
}
Thanks!