Jump to content
MakeWebGames

Recommended Posts

Posted

Hello all, in the userlist.php (for v2) how would I change

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

So that I can show information from the userstats table?

I tried different things and can't find away with my current knowledge....

Thanks!

Sp1d3r

www.chaosrelic.com

Posted

Re: Userlist.php

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

Not tested but should work

Posted

Re: Userlist.php

Thanks for the replay wicked but I got the same error I was getting when i tried to change it.

QUERY ERROR: Column 'userid' in order clause is ambiguous

Query was SELECT u.*,g.*,us.* FROM users u LEFT JOIN gangs g ON u.gang=g.gangID LEFT JOIN userstats us ON us.userid=u.userid ORDER BY userid ASC LIMIT 0,100

Sp1d3r

www.chaosrelic.com

Posted

Re: Userlist.php

 

$sql = sprintf("SELECT u.*, g.gangPREF, us.* " .
"FROM users u " .
"LEFT JOIN gangs g ON (u.gang = g.gangID) " .
"LEFT JOIN userstats us ON (u.userid = us.userid) " .
"ORDER BY %s %s LIMIT %u, 100", $by, $ord, $st);

$q = $db->query($sql);
Posted

Re: Userlist.php

Thank Magictallguy but I got the same error as above.

 

QUERY ERROR: Column 'userid' in order clause is ambiguous

Query was SELECT u.*, g.gangPREF, us.* FROM users u LEFT JOIN gangs g ON (u.gang = g.gangID) LEFT JOIN userstats us ON (u.userid = us.userid) ORDER BY userid ASC LIMIT 0, 100

The code is original v2 coding just FYI so theres no missing/special pieces if that helps.

Sp1d3r

www.chaosrelic.com

Posted

Re: Userlist.php

 

Thank Magictallguy but I got the same error as above.

 

QUERY ERROR: Column 'userid' in order clause is ambiguous

Query was SELECT u.*, g.gangPREF, us.* FROM users u LEFT JOIN gangs g ON (u.gang = g.gangID) LEFT JOIN userstats us ON (u.userid = us.userid) ORDER BY userid ASC LIMIT 0, 100

The code is original v2 coding just FYI so theres no missing/special pieces if that helps.

Sp1d3r

www.chaosrelic.com

Ah, I see why now too..

It's selecting the order by from the users link and that is selecting userid. userid exists in both the users and the userstats table - and that's why you're getting an error.. I can't think of a simple way to fix at the moment. Way too much on my mind.

Posted

Re: Userlist.php

 

could it be this

ORDER BY userid ASC LIMIT 0, 100

?

maybe

ORDER BY u.userid ASC LIMIT 0, 100

CE is so friggin' slow -.-

Your method would disable the users ability to change the order clause..

Try using:

$sql = sprintf("SELECT u.*, g.gangPREF, us.* " .
"FROM users u " .
"LEFT JOIN gangs g ON (u.gang = g.gangID) " .
"LEFT JOIN userstats us ON (u.userid = us.userid) " .
"ORDER BY u.%s %s LIMIT %u, 100", $by, $ord, $st);

$q = $db->query($sql);
Posted

Re: Userlist.php

 

$sql = sprintf("SELECT u.*, g.gangPREF, us.* " .

"FROM users u " .

"LEFT JOIN gangs g ON (u.gang = g.gangID) " .

"LEFT JOIN userstats us ON (u.userid = us.userid) " .

"ORDER BY u.%s %s LIMIT %u, 100", $by, $ord, $st);

$q = $db->query($sql);

Thanks that works.

What I was doing before you helped me was instead of using

us.*
I just used us.XXX where XXX is the field in the table.

Is there anything wrong with doing that? Just curious but the code you provided did work

+1

Sp1d3r

www.chaosrelic.com

Posted

Re: Userlist.php

 

$sql = sprintf("SELECT u.*, g.gangPREF, us.* " .

"FROM users u " .

"LEFT JOIN gangs g ON (u.gang = g.gangID) " .

"LEFT JOIN userstats us ON (u.userid = us.userid) " .

"ORDER BY u.%s %s LIMIT %u, 100", $by, $ord, $st);

$q = $db->query($sql);

Thanks that works.

What I was doing before you helped me was instead of using

us.*
I just used us.XXX where XXX is the field in the table.

Is there anything wrong with doing that? Just curious but the code you provided did work

+1

Sp1d3r

www.chaosrelic.com

Nothing wrong with that at all. But, as I don't know which parts of the table you wish to display, I selected all.

If you wish to speed up your code while using a MySQL query, only select what you need from a table instead of everything

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