Re: if then else statement not working

From: Date: Thu, 05 May 2005 17:34:22 +0000
Subject: Re: if then else statement not working
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-214566@lists.php.net to get a copy of this message
What am i doing wrong here, the output is always 'empty' <?php $result = mysql_query("SELECT username FROM users WHERE seatnum='seat1'") or die(mysql_error()); if (seatnum == seat1) { echo username; } else { echo 'empty'; } ?>
Just guessing since I'm not sure what you're trying to do, but... <?php $result = mysql_query("SELECT username FROM users WHERE seatnum='seat1'")
          or die(mysql_error());
list($username) = mysql_fetch_array($result, MYSQL_NUM); if ($seatnum == "seat1") { echo $username; }else { echo 'empty'; } ?> What I'm not seeing is where you set $seatnum in the first place and why you're doing the if/else at all since your mysql query will only return a username *if* seatnum='seat1' already so the above code I'm guessing will always print out $username (or blank if the query returns no results). Anyway, the above should get you going in the right direction... -philip

« previous php.general (#214566) next »