Hi Can somebody please give me the corect syntax for the following query, I am finding it difficult to pass the username of a session in a query. I have tried so many ways to implement this, but it just won't work... These are some of the methods I have tried! What am I doing wrong. It's in PHP by the way! $q = "SELECT user, message, senttime " ."FROM ".TBL_AUCTION_RESPONSES." WHERE user=".$session->username." ORDER BY senttime DESC"; $q = "SELECT user, message, senttime " ."FROM ".TBL_AUCTION_RESPONSES." WHERE user='.$session->username.' ORDER BY senttime DESC"; $q = "SELECT user, message, senttime " ."FROM ".TBL_AUCTION_RESPONSES." WHERE user='<?php echo $session->username;?>' ORDER BY senttime DESC"; Code (markup): If I use a string in the query as seen below in bolded letters, the query works just fine! $q = "SELECT user, message, senttime " ."FROM ".TBL_AUCTION_RESPONSES." WHERE user='grant' ORDER BY senttime DESC"; Can somebody tell me what the syntax should be for variables in a case like this Thanks Grant
$q = mysql_query("SELECT user, message, senttime " ."FROM ".TBL_AUCTION_RESPONSES." WHERE user='grant' ORDER BY senttime DESC");
LightGraphicz I know how to query the data base, I am using a seperate database php file that handels the actual queries ie: mysql_query I am having difficulty with the syntax for including a session variable ($session->username) into the query string which gets passed to database.php global $database; $q = "SELECT user, message, senttime " ."FROM ".TBL_AUCTION_RESPONSES." WHERE user="" & $session->username & "" ORDER BY senttime DESC"; $result = $database->query($q); Code (markup): Thanks for the quick response
global $database; $q = "SELECT user, message, senttime " ."FROM ".TBL_AUCTION_RESPONSES." WHERE user="" & $session>=username & "" ORDER BY senttime DESC"; $result = $database->query($q); you want it to be greater then or equal to or just greater then?
The code I suplied in my second post is not correct I was just trying out the double quotes, well actually I've been trying just about everything except the correct syntax
I am trying to pass the session user name in the query string but can't find the correct syntax or structure it should be in to work $q = "SELECT user, message, senttime " . "FROM " . TBL_AUCTION_RESPONSES . " WHERE user=" . $_SESSION['username'] . " ORDER BY senttime DESC"; Code (markup): I am not trying to do greater than or anything like that I have just been trying different way of structuring the queries, the username is part of a session array