Jump to content

IF statement problem with null


suess0r

Recommended Posts

Hi,

my table is set so if the field isn't filled out it's set as NULL, i want to only print out the records that aren't = to "NULL" but it prints out all of them and not just the ones that that have info in them and aren't = to NULL...

[quote]if (mysql_result($result_set, $i, "NS_Mon") != "NULL") {
$NSmon=mysql_result($result_set, $i, "NS_Mon");
echo'<br><b>Mon: </b>'.$NSmon.'';
} else {
echo'<br><b>No Specials Provided.</b>';
$NSmon="None";
}
if (mysql_result($result_set, $i, "NS_Tues") != "NULL") {
$NStues=mysql_result($result_set, $i, "NS_Tues");
echo'<br><b>Tue: </b>'.$NStues.'';
} else {
$NStues="None";
}
if (mysql_result($result_set, $i, "NS_Wed") != "NULL") {
$NSwed=mysql_result($result_set, $i, "NS_Wed");
echo'<br><b>Wed: </b>'.$NSwed.'';
} else {
$NSwed="None";
}
if (mysql_result($result_set, $i, "NS_Thur") != "NULL") {
$NSthur=mysql_result($result_set, $i, "NS_Thur");
echo'<br><b>Thr: </b>'.$NSthur.'';
} else {
$NSthur="None";
}
if (mysql_result($result_set, $i, "NS_Fri") != "NULL") {
$NSfri=mysql_result($result_set, $i, "NS_Fri");
echo'<br><b>Fri: </b>'.$NSfri.'';
} else {
$NSfri="None";
}
if (mysql_result($result_set, $i, "NS_Sat") != "NULL") {
$NSsat=mysql_result($result_set, $i, "NS_Sat");
echo'<br><b>Sat: </b>'.$NSsat.'';
} else {
$NSsat="None";
}
if (mysql_result($result_set, $i, "NS_Sun") != "NULL") {
$NSsun=mysql_result($result_set, $i, "NS_Sun");
echo'<br><b>Sun: </b>'.$NSsun.'';
} else {
$NSsun="None";
}[/quote]
Link to comment
Share on other sites

Should just do it with the sql statement

[code]$sql = "SELECT * FROM table WHERE field IS NOT NULL";[/code]

Also in php if you put single quotes around 'NULL' it is actually looking for the word NULL. Just use NULL without any quotes.

[code]if (mysql_result($result_set, $i, "NS_Mon") != NULL)[/code]

Ray
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.