PDA

View Full Version : Help with a query :(


N9ne
03-16-2003, 02:49 PM
What is the query to run (I'm guessing involves LEFT JOIN), to get the required information to display the title of the styleid a user is using?

Is a while() function required too? If so, what do I place? Are we fetching an array?

filburt1
03-16-2003, 02:51 PM
mysql> SELECT s.title FROM user u, style s WHERE u.userid = 1 AND s.styleid = u.styleid;
+------------+
| title |
+------------+
| Default vB |
+------------+
1 row in set (0.26 sec)

N9ne
03-16-2003, 03:12 PM
That query just gives me errors, what's the query I could place in a vB file?

$style=$DB_site->query("SELECT s.title FROM user u, style s WHERE u.userid = '$userinfo[userid]' AND s.styleid = u.styleid");

That also doesn't work, I'm not sure what to do, I just want to be able to put a variable in a template, and it output not the user viewing the page, but users' style sets...it's for the memberlist..

N9ne
03-16-2003, 03:37 PM
ok I figured it out for myself, I used this:


$style = $DB_site->query("SELECT title FROM user u, style s WHERE u.userid = '$userinfo[userid]' AND s.styleid = u.styleid");
while ($styleinfo=$DB_site->fetch_array($style)) {
$styleinfouser=$styleinfo[title];
}

filburt1
03-16-2003, 03:38 PM
Make sure $userinfo['userid'] (BTW, /me smacks N9ne for using constants instead of strings in array keys) is set correctly. The query works as you can see.

N9ne
03-16-2003, 04:13 PM
ok there must be something wrong with the code, because:

I have 3 users on my localhost (I just created some random users), and...

It shows nothing for me...

For the user below me in the memberlist, it shows the style I'm using...

For the 3rd user, it shows the second style on the board (there's only 2), even though he's using the first style...

I'm clueless, i'm about to give up this, I could've sworn something with LEFT JOIN must be done for this to work properly...

filburt1
03-16-2003, 04:24 PM
Check their styleids and that they're all 1 (i.e., not 0).

N9ne
03-16-2003, 04:29 PM
All styleids are correct.