Jump to content

[SOLVED] Help with if Statement


grozanc

Recommended Posts

Hello,

 

I have a field in a MySQL table that defaults to "empty" unless it's written over. I'm using the following code to assign a variable based on what's written in that MySQL field.

 

$query2  = "SELECT * FROM $table";
$row = mysql_fetch_assoc(mysql_query($query2));
if ($row['name'] == 'empty') { $joblink = "no download"; } else { $joblink = "download"; }; 

 

However, it doesn't seem to recognize the if statement and defaults to else part of the if statement regardless of what actually in the filed. Any ideas?

 

Thanks,

Gary

Link to comment
Share on other sites

<?php
$query2  = "SELECT * FROM $table";
$row = mysql_fetch_assoc(mysql_query($query2));
if (is_empty($row['name']))
{
$joblink = "no download"; 
} 
else 
{
$joblink = "download"; 
} 
?>

 

i do suspect how ever you want to check if its NULL in which case use is_null()

Link to comment
Share on other sites

If the data within the column field defaults to the string 'empty' and that's what you are (and were) checking against then technically it sempt right in the first place.

 

Not that it should matter but I tend to use strcmp for comparing strings.

 

Have you tried printing out the value, just to make sure there are some fields with that value? (may sound too daft, but we all do these things from time to time).

 

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.