|
Posted by Jerry Stuckle on 08/06/07 11:58
Bob Bedford wrote:
> Hi all,
>
> 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:
>
> $mode = 1;
> mysql_query($query...
> $mode = 2;
> mysql_query($query
>
> the first is OK, but the second isn't ok, it still uses the $mode = 1.
>
> Why ? how to fix it ?
> Bob
>
>
Bob,
I'm not clear - are you actually including the file where you have the
mysql_query() statement in your code? If so, please post the real code
you're using - pseudo-code seldom finds problems.
Also, I wouldn't do it like this. I'd place the query in a function,
and call the function, i.e.
function doQuery($m) {
$result = mysql_query("SELECT * FROM xxx... WHERE mode=$m");
return $result;
// or fetch the data and return it - whatever you wish
}
Alternatively, you could define the string in the include file such as:
$query = "SELECT * FROM xxx... WHERE mode=";
Then later say:
$result = mysql_query($query . $mode);
But this can cause other problems because it places a code dependency on
data external to the module. For instance, what if someone else defines
a variable $query? Or if you need to change the query itself (say add
another WHERE condition), how many places in your code would have to change?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|