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 .