> Is it possible to put variable operators in queries?

=I can see no reason why not - you're not actually putting the 'variable' in the 
'query', just using a PHP-variable to
build a PHP-string which will be sent to MySQL as a SQL query...

> I tried this (the real variable comes from a form)
> $Date_Operator =(">=");
> sql="SELECT * FROM poeple WHERE age $Date_operator 20";
> $result_id = mysql_query($sql);
>
> It doesn't work like this. I also tried:
> sql="SELECT * FROM poeple WHERE age \"$Date_operator\" 20"
> $result_id = mysql_query($sql);
> it didn't work either.


Sander,

First of all, may I recommend the liberal use of 'debug echo's. At this stage you 
don't know if the fault is in the
construction of the query, or within the PHP-MySQL interface, or... Recommend you 
insert something like echo "Query is
$sql" for your own health/sanity. Secondly how are you viewing the 'results' from the 
database to judge that "it doesn't
work"?

The reason for this comment is that "people" is spelled incorrectly, and unless this 
misspelling is consistent...
In similar vein, you have used the term "sql" in the assignment statements, but 
(rightly) $sql within the query and the
odd semi-colon (;) is missing too!

Regards,
=dn



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to