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 #172247 is a reply to message #172244] Tue, 08 February 2011 01:27 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On 07/02/11 23:03, Derek Turner 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;
>
> }
>
> 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.

From the manual:

> For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
> resultset, mysql_query() returns a resource on success, or FALSE on
> error.

Note that an empty result set is still a result set!

This might be neater, and allows you to use an integer for your loop:

$conn = mysql_connect($dbserver,$dbusername,$dbpassword);
$1 = 1;
$qryfmt = "select blah blah blah %02d blah blah blah %02d blah blah";

while ($result = mysql_query(sprintf($qryfmt,$i,$i),$conn) &&
mysql_num_rows($result) != 0) {
// do stuff with result
$i++;
}
[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 10 12:00:52 GMT 2024

Total time taken to generate the page: 0.04326 seconds