Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3200

Re: Setting variable to false in a WHILE loop

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Setting variable to false in a WHILE loop
Date 2011-09-24 09:14 -0400
Organization A noiseless patient Spider
Message-ID <j5kl4c$mbs$1@dont-email.me> (permalink)
References <a1536ef2-b1a4-473c-a6e8-93d1a7c800e2@k6g2000yql.googlegroups.com>

Show all headers | View raw


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@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Setting variable to false in a WHILE loop jwcarlton <jwcarlton@gmail.com> - 2011-09-23 20:53 -0700
  Re: Setting variable to false in a WHILE loop Jerry Stuckle <jstucklex@attglobal.net> - 2011-09-24 09:14 -0400
    Re: Setting variable to false in a WHILE loop tamouse <tamouse.lists@gmail.com> - 2011-09-28 11:28 -0700
      Re: Setting variable to false in a WHILE loop Tim Streater <timstreater@greenbee.net> - 2011-09-28 20:49 +0100
      Re: Setting variable to false in a WHILE loop Doug Miller <doug_at_milmacdotcom@example.com> - 2011-09-29 08:09 -0400
      Re: Setting variable to false in a WHILE loop Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-01 16:08 +0200

csiph-web