Re: variable operators in queries

From: Date: Fri, 19 Oct 2001 23:25:25 +0000
Subject: Re: variable operators in queries
References: 1  Groups: php.db php.general 
Request: Send a blank email to php-db+get-13551@lists.php.net to get a copy of this message
> 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

« previous php.db (#13551) next »