PDA

View Full Version : SQL Query Acting Weird


ZomgStuff
01-04-2008, 12:42 AM
https://vborg.vbsupport.ru/external/2008/01/48.jpg

It is weird, because I can call $username342342342342 just fine from a template, but if I change

$userinfo31221213 = fetch_userinfo($Entries['Date']);
to

$userinfo31221213 = fetch_userinfo($Entries['Author']);

It won't display? Why does it do this? I don't want to put my author column last.

Adrian Schneider
01-04-2008, 12:49 AM
You should really perform a LEFT JOIN on the user table instead of a nested fetch_userinfo() call.

Why would you use $Entries['Date'] ... shouldn't it be $Entries['Author']. Also, I'm surprised your query even executes because 'Date' is a reserved MySQL keyword.

Add this debug code to the end of your loop

var_dump($Entries);
var_dump($username342342342342); exit;

Finally, can you explain your logic behind it all? It's a bit confusing to me.

ZomgStuff
01-04-2008, 12:52 AM
You should really perform a LEFT JOIN on the user table instead of a nested fetch_userinfo() call.

Why would you use $Entries['Date'] ... shouldn't it be $Entries['Author']. Also, I'm surprised your query even executes because 'Date' is a reserved MySQL keyword.

Add this debug code to the end of your loop

var_dump($Entries);
var_dump($username342342342342); exit;

Finally, can you explain your logic behind it all? It's a bit confusing to me.


It should be Author, but for some reason it would only work if it was the last column in the table.

How do I do a LEFT JOIN?

Guest190829
01-04-2008, 07:54 AM
SELECT contestv.ID, contestv.Contest, contestv.Author, contestv.Location, contestv.Date, user.*
FROM " . TABLE_PREFIX ."contestview AS contestv
LEFT JOIN " . TABLE_PREFIX ."user AS user ON(user.username = contestv.Author)
WHERE contestv.ID = " . intval($contestID) . "


That is the gist of a LEFT JOIN...

Some other things: You should really use userid if you are currently using username...it is easier to index and better for normalization.

And column name are simpler to remember if all are lowercase IMO.

ZomgStuff
01-04-2008, 12:39 PM
Ah, thank you.

ZomgStuff
01-07-2008, 12:40 AM
Hm, I don't get it...


$queryMe = "SELECT contestv.ID, contestv.Contest, contestv.Author, contestv.Location, contestv.TheDate, user.*
FROM " . TABLE_PREFIX . "contestview AS contestv
LEFT JOIN " . TABLE_PREFIX . TABLE_PREFIX . "user AS user ON(user.username = contestv.Author)
WHERE contestv.Contest = " . intval($contestID);
$Entry = $db->query_read($queryMe);
while ($Entries = $db->fetch_array($Entry) )
{
eval('$contestEntries .= "' . fetch_template('contestview_bit') . '";');
}
https://vborg.vbsupport.ru/misc.php?do=bbcode
It freezes my internet browser.


Also Author is a userid.

Guest190829
01-08-2008, 12:36 PM
You are concatenating TABLE_PREFIX twice to the user table, and if Author is a userid, you need to join on user.userid not user.username