pocobueno1388 Posted September 24, 2006 Share Posted September 24, 2006 I got some help with this script the other day, but now I am trying to add pagination to the page. This is just a search script where users can type in information and it will pull it from the database and display the matching results, but that is not important.The query is written in a way where I can't really add something to it, here is the part of the code that I'm talking about:[code]$query = "SELECT `playerID`, `username`, `online`, `upgrade` FROM `players` WHERE 1";if($username) $query.=" AND `username` = '$username'";if($id) $query.=" AND `playerID` = '$id'";$result = mysql_query($query);[/code]To do pagination I would need to make the query like this:[code]$max_results = 10;$from = (($page * $max_results) - $max_results);$result = mysql_query("SELECT row FROM table WHERE condition LIMIT $from, $max_results");[/code]But as you can see I am kinda stuck having to make my $reslut query look like this:[code]$result = mysql_query($query);[/code]I can't add 'LIMIT $from, $max_results' anywhere after the mysql_query($query).I am sure there is a way, I just can't figure it out. Any help is appreciated =) Thanks Quote Link to comment Share on other sites More sharing options...
invincible_virus Posted September 24, 2006 Share Posted September 24, 2006 Add[code]$query.=" LIMIT $from, $max_results";[/code]before[code]$result = mysql_query($query);[/code]calling mysql_query($query) runs the query, so you have to prepare desired query with limits before you execute it. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted September 24, 2006 Author Share Posted September 24, 2006 That didn't give me any huge errors, so I am sure it will work. But it created a small one.[code]Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result[/code]Code:[code]$row = mysql_fetch_assoc($result);[/code]Thanks for the help :)EDIT: I guess it might be helpful if I post the new code, hah.[code]if($username) $query.=" AND `username` = '$username'";if($id) $query.=" AND `playerID` = '$id'";$max_results = 10;$from = (($page * $max_results) - $max_results);$query.=" LIMIT $from, $max_results";$result = mysql_query($query);$row = mysql_fetch_assoc($result);[/code] Quote Link to comment 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.