iceblox Posted October 29, 2007 Share Posted October 29, 2007 Hi Everyone, I have followed the tutorial on this website and i cant get the pagination to work. I have followed it 100% im must be being stupid. This is my code It seems to be displaying the next etc but not the link.. ANy ideas? <?php $connection = mysql_connect('localhost','user','password'); mysql_select_db('mobile'); if($_GET['NetworkName'] == "") { $net = ''; } else { $net = "NetworkName = '$_GET[NetworkName]' AND "; } if($_GET['FreeGift'] == "") { $net1 = ''; } elseif($_GET['FreeGift'] == "1") { $net1 = "FreeGift = ' ' AND "; } elseif($_GET['FreeGift'] == "0") { $net1 = "FreeGift != ' ' AND "; } else { $net1 = "FreeGift = '$_GET[FreeGift]' AND "; } if($_GET['CashBack'] == "") { $net2 = ''; } elseif($_GET['CashBack'] == "1") { $net2 = "AutoCashback = '1' AND "; } elseif($_GET['CashBack'] == "2") { $net2 = "OfferRental = TariffRental AND OfferCashBack = '0.00' AND "; } else { $net2 = ""; } $limit = 40; // Sets how many results shown per page $query_count = "SELECT count(*) FROM deals WHERE $net1 MonthlyCost BETWEEN 0 AND '{$_GET['MonthlyRental']}' AND $net PhoneCost BETWEEN 0 AND '{$_GET['PhoneCost']}' AND $net2 ContractLength BETWEEN 0 AND '{$_GET['ContractLength']}' AND FreeMins BETWEEN '{$_GET['FreeMins']}' AND 9999 AND FreeTxts BETWEEN '{$_GET['FreeTxts']}' AND 9999"; // Sets what we want to pull from the database // count(*) is better for large databases (thanks Greg!) $result_count = mysql_query($query_count); // Pulls what we want from the database $totalrows = mysql_num_rows($result_count); // This counts the number of users if(empty($page)){ // Checks if the $page variable is empty (not set) $page = 1; // If it is empty, we're on page 1 } $limitvalue = $page * $limit - ($limit); $query = "SELECT * FROM deals WHERE $net1 MonthlyCost BETWEEN 0 AND '{$_GET['MonthlyRental']}' AND $net PhoneCost BETWEEN 0 AND '{$_GET['PhoneCost']}' AND $net2 ContractLength BETWEEN 0 AND '{$_GET['ContractLength']}' AND FreeMins BETWEEN '{$_GET['FreeMins']}' AND 9999 AND FreeTxts BETWEEN '{$_GET['FreeTxts']}' AND 9999 LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die(mysql_error()); $totalrows = mysql_num_rows($result); if (mysql_num_rows($result) > 0) { echo '<table width=840>'; echo '<tr>'; echo '<td width=17% align=center bgcolor="#87C542"><b>Tariff</b></td>'; echo '<td width=50% align=center bgcolor="#87C542"><b>The Detail</b></td>'; echo '<td width=20% align=center bgcolor="#87C542"><b>The Price</b></td>'; echo '<td width=13% align=center bgcolor="#87C542"><b>Where To Buy</b></td>'; echo '</tr>'; while($row = mysql_fetch_row($result)) { if($rowcounter%2==1) $bgcolor="#F4F4F4"; else $bgcolor="#FFFFFF"; $price =$row[2] / $row[17]; $price2 =$row[1] - $row[2]; if($row[17] == "12") { $net = '<font color="#000099">' . $row[17] . ' Month Contract</font>'; } else { $net = '<font color="#FF0000">' . $row[17] . ' Month Contract</font>'; } if($row[7] == "0.00") { $deal = ' - <font color="#FF0000">' . $row[8] . ' Months FREE Line Rental</font>'; } elseif($row[5] >= "0.01") { $deal = ' includes £' . $row[5] . ' Cashback</b>'; } elseif($price2 == "0.00") { $deal = ' - <font color="#FF0000">' . $row[8] . ' Months FREE Line Rental</font>'; } elseif($row[7] < "$row[18]") { $deal = ' - ' . $row[8] . ' Months at £' . $row[7] . ''; } else { $deal = ''; } if($row[6] == "1") { $auto = '<font color="#FF0000">Automatic Cashback - No Redemtion Required!</font><br><br>'; } else { $auto = ''; } if($row[20] == "0") { $say2 = ''; } else { $say2 = '' . $row[20] . ' ' . $row[21] . ' minutes to any network '; } if($row[22] == "0") { $say3 = ''; } else { $say3 = 'plus ' . $row[22] . ' texts per month'; } echo '<tr bgcolor="' . $bgcolor . '">'; if($row[1] == "0") { $phone = '<b><font color="#FF0000">FREE</font> ' . $row[11] . ' ' . $row[12] . '</b>'; } else { $phone = '<b>' . $row[11] . ' ' . $row[12] . ' only £' . $row[1] . '</b>'; } if($row[4] == "") { $gift = ''; } else { $gift = ' with a <font color="#FF0000">FREE</font> ' . $row[4] . ''; } if($row[4] == "") { $giftimg = ''; } elseif($row[4] == "PAYG Handset") { $giftimg = ''; } else { $giftimg = ' <img src="images/' . $row[4] . '.jpg" alt="FREE ' . $row[4] . '" align=left>'; } if($row[22] == "0") { $say10 = ''; } else { $say10 = 'plus ' . $row[22] . ' texts per month'; } if($row[24] == "Vodafone") { $say4 = 'Voda ' . str_replace("£","£",$row[19] ) . ''; } elseif($row[24] == "O2") { $say4 = 'O2 ' . str_replace("£","£",$row[19] ) . ''; } elseif($row[24] == "Virgin") { $say4 = 'Virgin ' . str_replace("£","£",$row[19] ) . ''; } elseif($row[24] == "BT Mobile") { $say4 = 'BT Mobile ' . str_replace("£","£",$row[19] ) . ''; } else { $say4 = '' . str_replace("£","£",$row[19] ) . ''; } echo '<tr bgcolor="' . $bgcolor . '">'; echo '<td align=center><img src=' . $row[25] . '><br>' . $say4 . '<br>' . $net . '<br> £' . $row[18] . ' Per Month</td>'; echo '<td align=center>'; if($row[23] == "") { $tmob = ''; } else { $tmob = ' T-Mobile Flext gives you an Allowance of £' . $row[23] . ' to spend how you like on minutes or texts. This could allow you to have '; } echo'<img src="' . $row[14] . '" alt="' . $row[11] . ' ' . $row[12] . '" align=left> ' . $giftimg . ' ' . $phone . ' ' . $deal . ' ' . $gift . ' <br> ' . $auto . ' ' . $tmob . ' ' . $say2 . ' ' . $say3 . ' standard Line rental is £' . $row[18] . ' per month.</td>'; echo '<td align=center>Average line rental after cash back will be '; if($row[2] == "0.00") { echo' <font color="#FF0000">£' . number_format($price, 2, '.', '') . '</font><br><br>Total cost of this contract: <font color="#FF0000"><b>FREE</b></font></td>'; } else { echo' £' . number_format($price, 2, '.', '') . '<br><br>Total cost of this contract: £' . number_format($row[2], 2, '.', '') . '</td>'; } echo '<td align=center><a target="_blank" href=http://www.yoursite.com/banners.php?op=dealsclick&ID=' . $row[0] . '><img border=0 alt="' . $row[26] . '" src=' . $row[27] . '><br><br><img border=0 alt="Buy Now - ' . $row[26] . '" src=http://www.freemobilephonereviews.com/cron/buy.gif></a></td>'; echo '</tr>'; $rowcounter++; } echo '</table>'; if($page != 1){ $pageprev = $page--; echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); }else{ echo("NEXT".$limit); } } mysql_free_result($result); mysql_close($connection); ?>code] Quote Link to comment https://forums.phpfreaks.com/topic/75199-solved-pagination-help/ Share on other sites More sharing options...
iceblox Posted October 29, 2007 Author Share Posted October 29, 2007 Any one got any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/75199-solved-pagination-help/#findComment-380406 Share on other sites More sharing options...
cooldude832 Posted October 29, 2007 Share Posted October 29, 2007 check if you sql is erroring I didn't see any error reporting on it. Quote Link to comment https://forums.phpfreaks.com/topic/75199-solved-pagination-help/#findComment-380409 Share on other sites More sharing options...
iceblox Posted October 29, 2007 Author Share Posted October 29, 2007 Yeah its not erroring at all i think its having trouble getting the number of rows but im not sure how Quote Link to comment https://forums.phpfreaks.com/topic/75199-solved-pagination-help/#findComment-380410 Share on other sites More sharing options...
cooldude832 Posted October 29, 2007 Share Posted October 29, 2007 replace every $result = mysql_query($query); with $result = mysql_query($query) or die(mysql_error()); using the right variable names in place and check what happens. Quote Link to comment https://forums.phpfreaks.com/topic/75199-solved-pagination-help/#findComment-380411 Share on other sites More sharing options...
iceblox Posted October 29, 2007 Author Share Posted October 29, 2007 Yeah nothing but i have noticed when i add say &page=11 the prev button works and the results change but the next button doesnt work... Quote Link to comment https://forums.phpfreaks.com/topic/75199-solved-pagination-help/#findComment-380424 Share on other sites More sharing options...
iceblox Posted October 29, 2007 Author Share Posted October 29, 2007 When i print $totalrows i get 1 and when i print i get $result_count Resource id #6 So its deviding it by one which is probably why the next isnt working as it thinks there arent any more rows but im not sure how to fix it Quote Link to comment https://forums.phpfreaks.com/topic/75199-solved-pagination-help/#findComment-380434 Share on other sites More sharing options...
sasa Posted October 29, 2007 Share Posted October 29, 2007 change: $totalrows = mysql_num_rows($result_count); to $totalrows = mysql_result($result_count,0,0); $pageprev = $page--; to $pageprev = $page-1; $pagenext = $page+1; to $pagenext = $page+1; Quote Link to comment https://forums.phpfreaks.com/topic/75199-solved-pagination-help/#findComment-380503 Share on other sites More sharing options...
iceblox Posted October 29, 2007 Author Share Posted October 29, 2007 Sasa Thanks very much! It worked a treat! Thanks Very Much!!! Quote Link to comment https://forums.phpfreaks.com/topic/75199-solved-pagination-help/#findComment-380664 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.