Page 1 of 1

Help with Select statement in PHP code please

Posted: Sun Mar 29, 2009 12:19 pm
by joave
Hi there:

I cannot get a variable to evaluate properly in a select statement. I have confirmed that the variable $center_ref is getting assigned a value of 1 by an echo statement. I have also confirmed that when putting the value of the variable directly in the code I get the desired results. Here is the code snippet:

while ($games = mysql_fetch_array($game)) {
$id = $games['id'];
$date = $games['date'];
$time = $games['time'];
$hometeam = $games['hometeam'];
$visitingteam = $games['visitingteam'];
$field = $games['field'];
$center_ref = $games['center_ref']; (Following is the part I need help with)

$pick1= @mysql_query('Select firstname, lastname FROM refs
WHERE id="$center_ref"'); (This does NOT work)

$pick1= @mysql_query('Select firstname, lastname FROM refs
WHERE id=1; (This works)

Any help would be appreciated.

Thank you in advance,

Dave

Re: Help with Select statement in PHP code please

Posted: Sun Mar 29, 2009 12:23 pm
by tech603

Code: Select all

$pick1= @mysql_query('Select firstname, lastname FROM refs
WHERE id="$center_ref"'); (This does NOT work)
You should wrap the the variable in single quotes, and your query in double quotes.

Code: Select all

$pick1= @mysql_query("Select firstname, lastname FROM refs
WHERE id='$center_ref' "); (This does NOT work)
This should work.

Re: Help with Select statement in PHP code please

Posted: Sun Mar 29, 2009 12:39 pm
by joave
Yes that worked. Thank you VERY much :)