Reply to Re: [PHP] sql query

Your name:

Reply:


Posted by Jochem Maas on 03/03/05 16:29

Jason Petersen wrote:
> On Wed, 2 Mar 2005 13:02:39 +0200, William Stokes <kalles@operamail.com> wrote:
>
>>Hello
>>
>>Can someone explain this to me. I don't know how to read this.
>>
>>if (!$variable = mysql_query("select id,sessid from users where ...
>>
>>What is this "if(!"
>
>
> This is a way to run a SQL query, capture the return value, and
> perform an action if the query failed. For code readability, I would
> probably write that as two statements:
>
> $variable = mysql_query("SELECT * FROM blah");
> if(!$variable) { error_handler(mysql_error()); }

in terms of readability an alternative if to write it like so:

if(! ($variable = mysql_query("SELECT * FROM blah")) {
// do stuff
}

what you have to realise is that the expression '$variable = mysql_query("SELECT * FROM blah")'
has a return value itself - which just happens to be the same as the value of $variable.

to put it another way, when you do:

echo $variable;

your not saying:
"output the contents of this variable"
but your actually saying:
"output the result of the expression '$variable'"
it just so happens that the result of the expression is this case
if the contents of $variable.

hopefully you get what I mean!, no doubt there are others that can explain it better!

>
> See the documentation for information on mysql_query return values:
> http://us2.php.net/manual/en/function.mysql-query.php
>
> Jason
>

[Back to original 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

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