Bob Bedford wrote:
Hi all,
Hi Bob,
>
I've a problem and can't resolve it.
I've a include.inc.php file with only line is a huge query. to make it
simple, the query is $query = "select * from xxx where mode = ".$mode
Now, this file is included in an other PHP form. Here is the code:
So HERE sits the include?
You can think of an include of the code literally inserted at the point
of include.
So your include says:
$query = "select * from xxx where mode = ".$mode
I would expect this gives you a NOTICE that $mode isn't defined yet.....
Are you sure you have errorreporting configured allright??
$mode = 1;
mysql_query($query...
This doesn't change the $query itself.
$mode = 2;
mysql_query($query
the first is OK, but the second isn't ok, it still uses the $mode = 1.
I doubt the first was OK.
I think it fetches results for $mode=0, AND produces a notice.
>
Why ? how to fix it ?
If you need to put that query into an external file, I would doe it like
this:
In external file:
-------------
$rawquery = "SELECT * FROM xxx WHERE ($mode=**MODE**);";
--------------
And then if you need a query, replace **MODE** with the string you
actually need.
$realquery = str_replace("**MODE**",$mode,$rawquery);
and then use the $realquery.
You could also use prepared statements. It is a little bit more complex,
but I think it suits your needs.
In general: If you do not know what goes wrong, simply spit out the
query before executing, so you can see what you are doing.
Hope that helps.
Regards,
Erwin Moller
Bob