View Full Version : variable in mysql
Colin-Roberts
12-08-2010, 03:22 PM
i have this query:
$result = mysql_query("SELECT * FROM comments WHERE userwall='Colin Roberts' ORDER BY id DESC");
i want userwall to be a variable in relation to whose logged in.. how do i do this?
<?php echo $loggedin['username']; ?> echo's the the name of logged in user
Colin-Roberts
12-08-2010, 04:14 PM
wow nvm i figured it out
LMS16
12-08-2010, 06:35 PM
$result = mysql_query("SELECT * FROM comments WHERE userwall='<?php echo $loggedin['username']; ?>' ORDER BY id DESC");
Wow, Im glad you figured that out lol
Lew.
Colin-Roberts
12-08-2010, 09:12 PM
lewie for the record your way doesn't work, it gives errors.
Irrorate
12-08-2010, 09:56 PM
$result = mysql_query("SELECT * FROM comments WHERE userwall='<?php echo $loggedin['username']; ?>' ORDER BY id DESC");
Wow, Im glad you figured that out lol
Lew.
If you're using a result variable... you're going to have the PHP tags open already.
$result = mysql_query("SELECT * FROM comments WHERE userwall = $loggedin['username'] ORDER BY id DESC"); should work fine... I've not used PHP in a long time.
LMS16
13-08-2010, 06:24 AM
lewie for the record your way doesn't work, it gives errors.
Sorry lol, I should of known that. I was at work at the time
$result = mysql_query("SELECT * FROM `comments` WHERE` userwall` = '" . $loggedin['username'] . "' ORDER BY `id` DESC");
Thats how I would have coded it :) I like my full stops lol
Lew.
Apolva
13-08-2010, 10:45 AM
Sorry lol, I should of known that. I was at work at the time
$result = mysql_query("SELECT * FROM `comments` WHERE` userwall` = '" . $loggedin['username'] . "' ORDER BY `id` DESC");
Thats how I would have coded it :) I like my full stops lol
Lew.
Your backquotes are messed up :D
$result = mysql_query("SELECT * FROM `comments` WHERE `userwall` = '".mysql_real_escape_string($loggedin['username'])."' ORDER BY `id` DESC;");
LMS16
13-08-2010, 12:34 PM
Your backquotes are messed up :D
$result = mysql_query("SELECT * FROM `comments` WHERE `userwall` = '".mysql_real_escape_string($loggedin['username'])."' ORDER BY `id` DESC;");
Lol, I did it quickly :) I like to have spaces between my " . "'s lol
Lew.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2026 vBulletin Solutions Inc. All rights reserved.