Paging Still not working!?

admin

Administrator
Staff member
Paging doesn't work...initial result page displayed is correct with limited results and the links to the correct # of next pages. However, when a numbered link or NEXT is clicked...ALL records in database are returned.
It looks like the problem is that each time a link (ie #2 or #3 or NEXT) is clicked...the user is broght back into the original script below..thus making a new call to the database. Any thoughts?

Ok...here's the code:

$connection = mysql_connect ("localhost", "myinfo", "myinfo") or die("Couldnt make the connection");

$db = mysql_select_db("mydb", $connection) or die("Couldnt select database");

$limit = 10;

if ($user_id) {
$sqlcount = "SELECT * FROM mytable WHERE user_id LIKE '$user_id%'";
} else {
$sqlcount = "select * from mytable WHERE
my conditions per web form";
}
//i'm getting appropriate results


$sql_countresult = mysql_query($sqlcount, $connection) or die ("Couldnt execute query count");

$totalrows = mysql_num_rows($sql_countresult);

if(empty($page)){
$page=1;
}

$limitvalue1 = $page*$limit-($limit);
if ($user_id) {
$sql = "SELECT * FROM mytable WHERE user_id LIKE '$user_id%' LIMIT $limitvalue1, $limit";
} else {
$sql = "SELECT * FROM mytable WHERE conditions from web form LIMIT $limitvalue1, $limit";
}

$sql_result = mysql_query($sql, $connection) or die ("Couldnt execute query");

// display the records
while ($row = mysql_fetch_array($sql_result)) {
echo the records to web
}

if (mysql_num_rows($sql_result) < 0.01) {
echo "No matches found";
some other trivial includes
}

if($page !=1) {
$pageprev = $page -1;
echo "<a href=http://www.phpbuilder.com/board/archive/index.php/\"$PHP_SELF?page=$pageprev\"> PREV </a>";
}

$numofpages = $totalrows/$limit;

if ($numofpages > 1) {
for($i=1;$i<$numofpages+1;$i++) {
echo "<a href=\"$PHP_SELF?page=$i\"> $i </a>";
}
}

if($totalrows%$limit !=0) {
echo "<a href=\"$PHP_SELF?page=$i\"> $i </a>";
}

if (($totalrows-($limit*$page)) > 0) {
$pagenext = $page +1;
echo "<a href=\"$PHP_SELF?page=$pagenext\"> NEXT </a>";
}

Hope this helps to make the question a little clearer.
Thanks for the help!!
gary
 
Back
Top