Syntax issue using mysql select with where clause


#1

Ok I am doing something stupid.

$result = mysql_query('SELECT * FROM `main` WHERE `recnbr` = 10 ');

works exactly as expected, but$recnum = 10; $result = mysql_query('SELECT * FROM `main` WHERE `recnbr` = $recnum '); returns

Error performing query:Unknown column ‘$recnum’ in ‘where clause’
when I would expect the same result, what am I doing wrong?

#2

try
[php]
$result = mysql_query('SELECT * FROM main WHERE recnbr = '.$recnum); [/php]

Or you could do

[php]
$result = mysql_query(“SELECT * FROM main WHERE recnbr = $recnum”); [/php]

Note the use of the SINGLE quotes and DOUBLE quotes.


#3

Thank you!


#4

My Pleasure. 8)