shcKr- Posted July 28, 2008 Share Posted July 28, 2008 Hello, I need some help, i have this page and more like it: http://bluid.co.uk/new/products/bedroom.php?beds Now i tried adding a pagination script to it, but because i am splitting the items from the table 'bedroom' and putting them in different pages, the pagination script splits the items into pages via their id and not the results after that.. here is my code <? include "../includes/config.php"; if(!isset($_GET['page'])){#if there isnt a page set $page = 1; #sets page to one } else { $page = $_GET['page']; #if the page is set, get it from the URL } $div = 40; # five content posts per page $from = (($page * $div) - $div); $sql=mysql_query("SELECT * FROM `bedroom` ORDER BY `id` ASC LIMIT $from, $div"); while($row=mysql_fetch_array($sql)){ $i++; $id=$row['id']; $title=stripslashes($row['title']); $type=stripslashes($row['type']); $range=stripslashes($row['range']); $size1=stripslashes($row['size1']); $size2=stripslashes($row['size2']); $size3=stripslashes($row['size3']); $size4=stripslashes($row['size4']); $size5=stripslashes($row['size5']); $price=stripslashes($row['price']); $picsmall=stripslashes($row['filename']); $picbig=stripslashes($row['filename2']); $type2="chairs"; $chateau="chateau"; $valbonne="valbonne"; $moulin="moulin"; $alexandra="alexandra"; $brookes="brookes"; $size1 = str_replace( " ", "<br>", $size1 ); $size2 = str_replace( " ", "<br>", $size2 ); $size3 = str_replace( " ", "<br>", $size3 ); $size4 = str_replace( " ", "<br>", $size4 ); $size5 = str_replace( " ", "<br>", $size5 ); $range = str_replace( "chateau", "<a href='chateau.php'>The Chateau Collection</a>", $range ); $range = str_replace( "valbonne", "<a href='valbonne.php'>The Valbonne Collection</a>", $range ); $range = str_replace( "moulin", "<a href='moulinnoir.php'>The Moulin Noir Collection</a>", $range ); $range = str_replace( "alexandra", "<a href='alexandra.php'>The Alexandra Range</a>", $range ); $range = str_replace( "brookes", "<a href='brookes.php'>The Brookes Range</a>", $range ); if($size1 == "") $result='n/a / n/a'; if($size2 == "") $result='n/a / n/a'; if($size3 == "") $result='n/a / n/a'; if($size4 == "") $result='n/a / n/a'; if($size5 == "") $result='n/a / n/a'; if($type == $type2){ ?> <div style="position:relative;float:left;margin-left:5px;margin-right:5px;"><table width="344" height="185" border="0" cellpadding="0" cellspacing="2" bgcolor="#fbfbfb"> <tr> <td height="153" rowspan="3" background="images/bedroom/chairs/<?php echo "$picsmall"; ?>"><div class="prodimg"><a href="images/bedroom/chairs/<?php echo "$picbig"; ?>" target="_blank">(Click To Enlarge)</a></div></td> <td height="120" colspan="5" style="font-size:14px;font-weight:bold"><?php echo "$title"; ?></td> </tr> <tr> <td height="10" colspan="5"><?php echo "$range"; ?></td> </tr> <tr style="font-weight:bold;font-size:10px;"> <td width="46" align="center" bgcolor="#f1f3f3">Length</td> <td width="46" align="center" bgcolor="#f1f3f3">Width</td> <td width="46" align="center" bgcolor="#f1f3f3">Height</td> <td width="46" align="center" bgcolor="#f1f3f3">Depth</td> <td width="46" align="center" bgcolor="#f1f3f3">Diameter</td> </tr> <tr style="font-size:10px;"> <td bgcolor="#f1f3f3">Imperial (<strong>inch</strong>)<br /> Metric (<strong>mm</strong>)</td> <td width="46" height="27" align="center" bgcolor="#f1f3f3"><?php echo "$size1"; ?></td> <td width="46" height="27" align="center" bgcolor="#f1f3f3"><?php echo "$size2"; ?></td> <td width="46" height="27" align="center" bgcolor="#f1f3f3"><?php echo "$size3"; ?></td> <td width="46" height="27" align="center" bgcolor="#f1f3f3"><?php echo "$size4"; ?></td> <td width="46" height="27" align="center" bgcolor="#f1f3f3"><?php echo "$size5"; ?></td> </tr> </table></div><? } } ?> <div style="position:relative;float:left;width:600px;margin:auto;text-align:center;margin-top:15px"> <? ##show the pagingation at the bottom of the page $numberoftopics = mysql_num_rows(mysql_query("SELECT * FROM bedroom")); #count the amount of pages $div = 40; #Divide number of topics by 5, to see how many pages there will be. $numberofpages = $numberoftopics / $div; # ditto $ceil = ceil ($numberofpages); #not entierly sure what this does but it is a function i guess works :/ for ($x=0; $x < $ceil; $x++) {#start outputting the pages with the for loop. starting value = 0, ending condition = the ammount of pages there are (where to stop), incretement is plus 1. $y = $x + 1; #increase the page to the for loop's limit if ($y != 0){ # we dont want to have a page=0 so we only show the link if the page doesnt equal 0 echo ("<a href='bedroom.php?$type2&page=$y'>$y</a> "); # echo the page links }#close the if statement }#close the for loop ?></div> Link to comment https://forums.phpfreaks.com/topic/116954-pagination-help-again/ Share on other sites More sharing options...
shcKr- Posted July 31, 2008 Author Share Posted July 31, 2008 still need help with this =[ Link to comment https://forums.phpfreaks.com/topic/116954-pagination-help-again/#findComment-604319 Share on other sites More sharing options...
JasonLewis Posted July 31, 2008 Share Posted July 31, 2008 Hang on, so whats wrong with it? Oh and I looked at your comments. Just for future reference: ceil() = round a number up, so 4.2 would become 5 etc etc. floor() = round a number down, so 4.6 would become 4 etc etc. Easy way to remember, the ceiling is UP and the floor is DOWN. Link to comment https://forums.phpfreaks.com/topic/116954-pagination-help-again/#findComment-604322 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.