Jump to content
MakeWebGames

Recommended Posts

Posted

This is the query for the user list page.

$q=$db->query("SELECT u.*,g.* FROM users u LEFT JOIN gangs g ON u.gang=g.gangID ORDER BY $by $ord LIMIT $st,50");

 

What im wondering is how to make it so it only shows the users in the same location as the user viewing the list.

I have no idea where to go I've tried this a few different ways.

 

$q=$db->query("SELECT u.*,g.* FROM users u LEFT JOIN gangs g ON u.gang=g.gangID ORDER BY $by $ord WHERE u.location={$ir['location']} LIMIT $st,50");

 

which prints out the error

QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE u.location=2 LIMIT 0,50' at line 1
Query was SELECT u.*,g.* FROM users u LEFT JOIN gangs g ON u.gang=g.gangID ORDER BY userid ASC WHERE u.location=2 LIMIT 0,50

 

I'm not very good with sql yet.

Any ideas?

Posted

Re: [V2] User List Question

The ORDER clause goes AFTER the WHERE, not before

 

$sql = sprintf(
"SELECT u.*, g.* " .
"FROM users u " .
"LEFT JOIN gangs g ON (u.gang = g.gangID) " .
"WHERE (u.location = %u) " .
"ORDER BY %s %s LIMIT %u, 50", $ir['location'], $by, $ord, $st);
$q = $db->query($sql);

 

I would also suggest filtering what people order by...

Try using

&ord=blah

somewhere in the URL..

Posted

Re: [V2] User List Question

thanks guys this worked for me :-)

I believe the $ord and the $by are set by the user clicking on Level | Ascending...

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.   Paste as plain text instead

  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...