FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Will this work?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Will this work? [message #172245 is a reply to message #172244] Mon, 07 February 2011 23:28 Go to previous messageGo to previous message
Robert Heller is currently offline  Robert Heller
Messages: 60
Registered: December 2010
Karma:
Member
At 7 Feb 2011 23:03:15 GMT Derek Turner <frderek(at)cesmail(dot)net> wrote:

>
> How long and complicated can a while condition be?
>
> I want to:
>
> define a string variable ($i) starting at "01"
> use this in a mysql query
> increment the string
> dropout of the while when a zero result comes back from mysql
>
> So, would something like:
>
> while ($sql="some multi-lined mysql query containing $i twice" &&
> $result=mysql($conn, $sql)){
>
> do some stuff including incrementing $i;
>
> }

Wouldn't this be a more sensable solution:

function largequery($conn,$i) {
$sql="some multi-lined mysql query containing $i twice";
return mysql($conn, $sql);
}

function increment(&$i) {
/* do a string increment of $i */
}

for ($i="01";$result=largequery($conn,$i);increment($i)) {
do some stuff;
}

Functions exist for a reason.

>
> presumably the first condition will always return true, will the second
> return false if no matches are found? Can a while condition run over
> several lines like this? The manual doesn't seem to say.

Yes, a while condition can run over several lines. Mind your
continuation characters... OTOH, if you have something like that, it
usually makes sense to put such things in functions. Makes the code
much easier to read and maintain. Bottom line: multi-line conditions are
possible, but there is little real need to do that.

>

--
Robert Heller -- 978-544-6933 / heller(at)deepsoft(dot)com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Question about binary transfers in POST requests
Next Topic: file_put_contents not creating file
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 23:44:12 GMT 2024

Total time taken to generate the page: 0.04202 seconds