grozanc Posted April 5, 2009 Share Posted April 5, 2009 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 Quote Link to comment Share on other sites More sharing options...
mentalist Posted April 5, 2009 Share Posted April 5, 2009 What do you mean, empty? if ($row['name'] == 'empty') or if ($row['name'] == empty) or if ($row['name'] == '') etc... Quote Link to comment Share on other sites More sharing options...
Fruct0se Posted April 5, 2009 Share Posted April 5, 2009 Try: <?php $query2 = mysql_query("SELECT * FROM $table"); while ($row = mysql_fetch_assoc($query2)) { extract($row); if ($name == "empty") { $joblink = "no download"; } else { $joblink="download" } } ?> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 5, 2009 Share Posted April 5, 2009 <?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() Quote Link to comment Share on other sites More sharing options...
grozanc Posted April 5, 2009 Author Share Posted April 5, 2009 What do you mean, empty? if ($row['name'] == 'empty') or if ($row['name'] == empty) or if ($row['name'] == '') etc... "empty" is the actual text information is the table column. Quote Link to comment Share on other sites More sharing options...
Fruct0se Posted April 5, 2009 Share Posted April 5, 2009 Isnt $row returning an array? So if you wanted to check the name of one row you would have to reference it $row[0]['name] seeing as he is SELECTING *? That is why in my previous post I extracted the rows first. Quote Link to comment Share on other sites More sharing options...
grozanc Posted April 5, 2009 Author Share Posted April 5, 2009 Hello All, Thanks for the help. I didn't find a solution, but I did realize that my line of questioning wasn't going to solve this problem. Again, thanks! Quote Link to comment Share on other sites More sharing options...
mentalist Posted April 5, 2009 Share Posted April 5, 2009 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). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.