Jump to content

Problem with query...


pocobueno1388

Recommended Posts

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.