Help with Select statement in PHP code please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joave
Forum Newbie
Posts: 3
Joined: Sun Mar 29, 2009 12:09 pm

Help with Select statement in PHP code please

Post 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
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: Help with Select statement in PHP code please

Post 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.
joave
Forum Newbie
Posts: 3
Joined: Sun Mar 29, 2009 12:09 pm

Re: Help with Select statement in PHP code please

Post by joave »

Yes that worked. Thank you VERY much :)
Post Reply