Trekky1700 Posted April 20, 2010 Share Posted April 20, 2010 Hello, this is my first post. I have been using PHP for a few months now, and am working on my second PHP website. It's more of a test than anything, with databases. But I've run into a problem :'(. I've made a site where users can add "posts" to the database (think the site fmylife.com). I want results from the database to display in pages within the page, just like on the site. I used a tutorial for a php search that displays results from the database in pages, but can't get it to work. It implements well, but the pages won't change. Here's the code: <?php mysql_connect("l-------","-------"); mysql_select_db("--------"); $limit = '10'; $query = "select * from ------- order by date DESC"; $numresults = mysql_query ($query) or die ("Couldn't execute query: Reason; ".mysql_error()); $row_num_links_main =mysql_num_rows ($numresults); $row_count += $row_num_links; if(!isset($s)) $s=0; $query .= " LIMIT $s,$limit" ; $numresults = mysql_query ($query) or die ("Couldn't execute query: Reason; ".mysql_error()); while($row = mysql_fetch_array($numresults)) { echo "<tr><td class=td_main><table class=posts><tr><td width=93% class=tdsubmission>{$row['submission']}</td></tr> <tr class=tr_info><td>Submitted by {$row['nickname']} at {$row['date']}.</td> <td>Flags: {$row['flagged']}</td></tr></table>"; $count++ ; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($row_num_links_main/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($row_num_links_main%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $row_num_links_main) { $a = $row_num_links_main ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $row_num_links_main</p>"; ?> Thank you in advance for any help/insight you can provide . Link to comment https://forums.phpfreaks.com/topic/199090-database-results-on-multiple-pages/ Share on other sites More sharing options...
Ken2k7 Posted April 20, 2010 Share Posted April 20, 2010 1. How does the value $s change? I can't find the line where it changes. 2. To get the number of entries, it'll be faster to use COUNT. The order by doesn't affect anything so I left it out. SELECT COUNT(*) AS num_rows FROM table; Link to comment https://forums.phpfreaks.com/topic/199090-database-results-on-multiple-pages/#findComment-1044985 Share on other sites More sharing options...
Trekky1700 Posted April 20, 2010 Author Share Posted April 20, 2010 1. How does the value $s change? I can't find the line where it changes. 2. To get the number of entries, it'll be faster to use COUNT. The order by doesn't affect anything so I left it out. SELECT COUNT(*) AS num_rows FROM table; I have no idea, I can give you a link to the tutorial I used parts of. http://www.designplace.org/scripts.php?page=1&c_id=25 Link to comment https://forums.phpfreaks.com/topic/199090-database-results-on-multiple-pages/#findComment-1044987 Share on other sites More sharing options...
Ken2k7 Posted April 20, 2010 Share Posted April 20, 2010 It's good to use a tutorial, but useless if you don't understand it. I said that the variable $s never changes. So that's different. See if you can find out how the tutorial manage to change the variable that your $s is mimicking. Link to comment https://forums.phpfreaks.com/topic/199090-database-results-on-multiple-pages/#findComment-1044989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.