You are here: Re: [PHP] if then else statement not working « PHP « IT news, forums, messages
Re: [PHP] if then else statement not working

Posted by Philip Hallstrom on 05/05/05 20:34

> 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация