Northern Flame Posted August 20, 2007 Share Posted August 20, 2007 i read through a tutorial here on phpfreaks and i used the pagination script. it worked fine for the most part, but their were a few problems on it. i fixed most of them but now i cant fix this one..... where it is suppose to show the pages, PREV 1 2 3 4 5 6 7 8 NEXT it only shows this PREV 1 the "PREV" and "1" link do point to the correct page and everything, but why wont it show the other pages? heres the part in the script that is suppose to show the pages.... for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." | "); }else{ echo('<a href='.$PHP_SELF.'?page='.$i.'">'.$i.'</a> | '); } } can anyone please help? Link to comment https://forums.phpfreaks.com/topic/65748-pagination/ Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 can you echo $numofpages Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328432 Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Author Share Posted August 20, 2007 but that would only echo the number of pages, i want each page echoed individually as a link Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328434 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 your code looks fine, so you should echo $numofpages to make sure that is not the problem but its 2:30 here and i need sleep so i could be wrong Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328438 Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Author Share Posted August 20, 2007 lol alright, ill give it a try Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328439 Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Author Share Posted August 20, 2007 i tried it but it didnt echo anything Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328444 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 can you post the rest of the code please Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328446 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Share Posted August 20, 2007 i tried it but it didnt echo anything probably a stupid question, but where does it get $numofpages? i would say thats not detecting the correct amount of pages Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328448 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 it gets it from where ever you declared it Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328452 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Share Posted August 20, 2007 doh, sorry, i did warn you it may have been a stupid question lol, its 2.30am here and ive only been learning php for a week or so.. fun fun, anyway, sorry to hijack your thread Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328454 Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Author Share Posted August 20, 2007 <?php include('includes/headerf.php'); echo '<div id=body align=center>'; $localhost = 'localhost'; $user = 'user'; $password = 'pass'; $database = 'database'; @mysql_connect($localhost, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER"); @mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB"); $limit = 10; $query_count = "SELECT count(*) FROM ringtones"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); $PHP_SELF = $_SERVER['PHP_SELF']; if(empty($page)){ $page = 1; } else{ $page = $_GET['page']; } $limitvalue = $page * $limit - ($limit); $query = "SELECT * FROM ringtones ORDER BY artist LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if($page != 1){ $pageprev = $page - 1; echo('<a href="'.$PHP_SELF.'?&page='.$pageprev.'">«PREV</a> | '); }else{ echo("<font color=red>«PREV</font> | "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo('<font color=red>'.$i."</font> | "); }else{ echo('<a href='.$PHP_SELF.'?page='.$i.'">'.$i.'</a> | '); echo $numofpages; } } if(($totalrows % $limit) != 0){ if($i == $page){ echo('<font color=red>'.$i."</font> | "); }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»</a><br><br>"); }else{ echo("<br><br>"); } if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } $bgcolor = "#E0E0E0"; // light gray while($row = mysql_fetch_array($result)){ if ($bgcolor == "#E0E0E0"){ $bgcolor = "#FFFFFF"; }else{ $bgcolor = "#E0E0E0"; } if($row['full'] == 'yes'){ echo '<a href="/qcp/full/'.$row["file"].'.qcp">'.$row["name"].' - '.$row["artist"].' - <font color=black>FULL!</font></a><br><br>'; } else{ echo '<a href="/qcp/part/'.$row["file"].'.qcp">'.$row["name"].' - '.$row["artist"].'</a><br><br>'; } } mysql_free_result($result); echo '</div>'; include('includes/template.php'); ?> Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328455 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 on your mysql query and num rows can you use or die(mysql_error()); it wasnt a dumb question as we all have to start somewhere Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328459 Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Author Share Posted August 20, 2007 alright let me try that Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328461 Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Author Share Posted August 20, 2007 it didnt tell me any error Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328463 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 bummer oh well, ill check after i have had some sleep, sorry! Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328466 Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Author Share Posted August 20, 2007 lol alright thanks for trying to help though Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328467 Share on other sites More sharing options...
chocopi Posted August 20, 2007 Share Posted August 20, 2007 Well now I am awake, I can assure that your for loop works fine, as long you set $numofpages. This obviously means the problem is with either $totalrows or $limit. And as you manually do $limit it means the problem is with $totalrows! So i recommend you check $query_count = "SELECT count(*) FROM ringtones"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); So add or die(mysql_error()); on to them to check everything is working. Also can you add error_reporting(E_ALL);[/php underneath the <?php, so its the first thing with in the php tags ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-328817 Share on other sites More sharing options...
Northern Flame Posted August 20, 2007 Author Share Posted August 20, 2007 thanks, i will make sure all the variables are set. Link to comment https://forums.phpfreaks.com/topic/65748-pagination/#findComment-329113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.