jmholl5 Posted March 20, 2009 Share Posted March 20, 2009 Let me start by saying I am very new to php and mysql. I am building a baseball team website and have a table that has class, playername, award1, award2, award3, award4, award5 as fields. The award fields are by default NULL. Each player wins a different amount of awards so I want to ignore fields that are NULL and I can't figure out how to do it. This is what I have right now. <? include("phpscripts/connect.php"); $query = "SELECT class,playername,award1,award2,award3,award4,award5 FROM playerrecognitions ORDER BY class DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array( $result )) { echo "<h3>"; echo $row['class']; echo "</h3><h4>"; echo $row['playername']; echo "</h4><ul>"; echo "<li>"; echo $row['award1']; echo "</li>"; echo "<li>"; echo $row['award2']; echo "</li>"; echo "<li>"; echo $row['award3']; echo "</li>"; echo "<li>"; echo $row['award4']; echo "</li>"; echo "<li>"; echo $row['award5']; echo "</li>"; echo "</ul>";} ?> I tried using an if statement but I couldn't make it work. Any help is greatly appreciated. Thanks. Quote Link to comment Share on other sites More sharing options...
btherl Posted March 20, 2009 Share Posted March 20, 2009 A better database design is having just three columns: class, playername, award. Then if you want multiple awards for a player, you add multiple rows to the table. For example Class Playername Award 1 John Best drinker 1 John Best sarcasm 2 Bob Worst BO Then you don't need to worry about nulls because they're not there. If you really do want to keep your current database structure and detect nulls, you can do this: if ($row['award4'] !== null) { echo $row['award4']; echo "</li>"; echo "<li>"; } Quote Link to comment Share on other sites More sharing options...
jmholl5 Posted March 20, 2009 Author Share Posted March 20, 2009 Thanks. I don't know why I didn't think to design my table that way. Thanks Again. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 why not just add a default expression/number to the database field. 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.