PHP Pagination, can someone help please?

Status
Not open for further replies.

chibib0

New Member
Messages
46
Reaction score
0
Points
0
I tried to program my php pagination but i get this:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/chibib0/public_html/memberspage.php on line 295

What supposed to be my problem?

Here's my php code that use pagination:
<?

$dbhost = "localhost";
$dbname = "wawa";
$dbuser = "wawa";
$dbpass = "wawa";
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}

$max_results = 10;

$from = (($page * $max_results) - $max_results);

$sql = mysql_query("SELECT * FROM users LIMIT $from, $max_results");

while($row = mysql_fetch_array($sql)){
echo "<tr>";
echo "<td class='tdrow1' width='10%' align='center'><br><img src='http://i238.photobucket.com/albums/ff19/tanabe84/Icon/user_info_48.png'><br />$row[name]<br /><br></td>";
echo "<td class='tdrow2' width='50%' align='center' padding='2px'><img src='http://i158.photobucket.com/albums/t90/junglejanelee/icon_arrow_sm.gif'> <a href='http://profiles.friendster.com/$row[id]' target='_new'>http://profiles.friendster.com/$row[id]</a></td>";
echo "<td class='tdrow1' width='5%' align='center'><span style='background:#000;border: 1px #fff solid;padding:2px;font-family:verdana;font-size:7px'>$row[visits]</span></td>";
}

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pages"),0);

$total_pages = ceil($total_results / $max_results);

echo "<center>Select a Page<br />";

if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}

if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";

?>
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
I don't know how your db is set up, but perhaps you need to change "FROM pages" to "FROM users" in this line:

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pages"),0);
 
Status
Not open for further replies.
Top