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
Re: Setting variable to false in a WHILE loop [message #175436 is a reply to message #175434] Sat, 24 September 2011 13:14 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 9/23/2011 11:53 PM, jwcarlton wrote:
> 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)) {
>

Why complicate things? Why not just use

if ($text !== false)


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[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: Thu Nov 28 06:37:43 GMT 2024

Total time taken to generate the page: 0.04304 seconds