NealeWeb Posted April 11, 2011 Share Posted April 11, 2011 I am building my uncle an online music catalogue and am trying to use pagination http://www.phpeasycode.com/pagination/ but for some reason it is only showing the cat_id data from the databse and even then its only the last entry. I need it to show all cat_id, song, artist and year from the database and not just the same ones over and over again. Here is a link to the page so you can see whats happening: http://www.nealeweb.com/steven2/ And here is the code, Can anybody tell me where i have gone wrong please. $rpp = 24; // results per page $adjacents = 4; $page = intval($_GET["page"]); if($page<=0) $page = 1; $reload = $_SERVER['PHP_SELF']; // connect to your DB: $dbHost = ""; $dbUser = ""; $dbPass = ""; $dbname = ""; $db = mysql_connect($dbHost,$dbUser,$dbPass); mysql_select_db($dbname,$db); // select appropriate results from DB: $requete = "SELECT cat_id, song, artist, year FROM tracks ORDER BY cat_id asc"; $result = mysql_query ($requete,$db); // count total number of appropriate listings: $tcount = mysql_num_rows($result); // count number of pages: $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; while(($count<$rpp) && ($i<$tcount)) { mysql_data_seek($result,$i); $query = mysql_fetch_array($result); // output each row: echo'<tr> <td valign="top" width="112" height="27"><span class="font">'.$catno.'</span></td> <td valign="top" width="536" height="27"><span class="font">'.$songname.'</span></td> <td valign="top"><span class="font" height="27">'.$artistname.'</span></td> <td valign="top" width="80" height="27"><span class="font">'.$ryear.'</span></td> </tr>'; $i++; $count++; } // call pagination function: include("paginate.php"); echo paginate_three($reload, $page, $tpages, $adjacents); Quote Link to comment https://forums.phpfreaks.com/topic/233403-pagination-help/ Share on other sites More sharing options...
NealeWeb Posted April 11, 2011 Author Share Posted April 11, 2011 Ok this time i managed to get it to display the results correctly but now i can only get the first page, when i go to next page it says not found. Here is the code and the link: http://www.nealeweb.com/steven2/ <?php $rpp = 24; // results per page $adjacents = 4; $page = intval($_GET["page"]); if($page<=0) $page = 1; $reload = $_SERVER['PHP_SELF']; $dbhost = "localhost"; $dbuser = ""; $dbpass = ""; $dbname = ""; // connect to your DB: $link_id = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname, $link_id); // select appropriate results from DB: $sql = "SELECT * FROM tracks ORDER BY cat_id asc"; $result = mysql_query($sql, $link_id); // count total number of appropriate listings: $tcount = mysql_num_rows($result); // count number of pages: $tpages = ($tcount) ? ceil($tcount/$rpp) : 3; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; while(($count<$rpp) && ($i<$tcount)) { mysql_data_seek($result,$i); $row = mysql_fetch_array($result); $catno = $row['cat_id']; $songname = $row['song']; $artistname = $row['artist']; $ryear = $row["year"]; // output each row: echo'<tr> <td valign="top" width="112" height="27"><span class="font">'.$catno.'</span></td> <td valign="top" width="536" height="27"><span class="font">'.$songname.'</span></td> <td valign="top"><span class="font" height="27">'.$artistname.'</span></td> <td valign="top" width="80" height="27"><span class="font">'.$ryear.'</span></td> </tr>'; $i++; $count++; } include("pagination3.php"); echo paginate_three($reload, $page, $tpages, $adjacents); ?> Quote Link to comment https://forums.phpfreaks.com/topic/233403-pagination-help/#findComment-1200277 Share on other sites More sharing options...
jcbones Posted April 12, 2011 Share Posted April 12, 2011 I looked at those functions, and they do NOT build the link's right. I would suggest using basic-pagination. Then maybe you could go back and fix the link builds. Hint: Your current link it built like: http://www.nealeweb.com/steven2/index.php&page=3 However, it should be built like: http://www.nealeweb.com/steven2/index.php?page=3 <- it works on your server SEE Quote Link to comment https://forums.phpfreaks.com/topic/233403-pagination-help/#findComment-1200328 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.