You are here: Re: include file and variable « PHP Programming Language « IT news, forums, messages
Re: include file and variable

Posted by Matt Madrid on 08/06/07 17:00

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
>
>

$query will have the value of $mode as it was when you first included the file.
Changing $mode later won't change what's in $query.

The easiest way to do what you want is to use sprintf()

$query = "select * from xxx where mode = %d";

$mode = 1;
mysql_query(sprintf($query,$mode));


$mode = 2;
mysql_query(sprintf($query,$mode));


HTH..
Matt M.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация