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

Home » Imported messages » comp.lang.php » Setting variable to false in a WHILE loop
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Setting variable to false in a WHILE loop [message #175434] Sat, 24 September 2011 03:53 Go to previous message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma:
Member
I'm doing a MySQL query, then running a WHILE loop on it, like so:

while (list($id, $title, $text) = mysql_fetch_row($sth)) {
if ($text) {
// do whatever
}
}

The problem that I'm having is that sometimes, it's possible for $text
to equal "" instead of NULL. I use it as a quick way to check whether
the row is new (in which case $text is NULL), or if it's been updated
(in which case $text is ""), without requiring an additional field.

I know that I could just say:

if ($text && ($text != "")) {

And I could move the list() inside of the loop, like so:

while ($row = mysql_fetch_row($sth) {
$text = false;
list($id, $title, $text) = $row;

if ($text) {
// do whatever
}
}


But I'm curious if there's a way to reset $id, $title, and $text to
false at the beginning of the loop. Something like:

// Just a mock-up, using "my" from Perl
while (my(list($id, $title, $text)) = mysql_fetch_row($sth)) {
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Contact Form
Next Topic: OCI.DLL and libcs.dll?
Goto Forum:
  

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

Current Time: Fri Sep 20 19:32:35 GMT 2024

Total time taken to generate the page: 0.04145 seconds