bigbenbuilders Posted September 14, 2009 Share Posted September 14, 2009 I need that if the database field is empty it displays a message. Here is what I have tried but I know that the fields have information and is displaying N/A. My if statement must be wrong or if any one knows a better way to do it would be great. Thanks in advance! <?php // Connect database. $host=""; // Host name. $db_user=""; // MySQL username. $db_password=""; // MySQL password. $database=""; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); $result=mysql_query("SELECT * FROM financial WHERE financial.Scholarship_group='Art' AND financial.Type='Scholarship'"); ?> <?php while($row=mysql_fetch_assoc($result)){ ?> <strong>Name: <?php echo $row['Name']; ?></strong><br> <strong>Selection Criterion:</strong> <?php if (mysql_num_rows($row) == 0) { echo "N/A"; } else { echo $row['Selection_Criterion']; } ?> <br> <strong>Award Information:</strong> <?php if (mysql_num_rows($row) == 0) { echo "N/A"; } else { echo $row['Award_Information']; } ?> <?php } // End while loop. ?> Quote Link to comment Share on other sites More sharing options...
bigbenbuilders Posted September 14, 2009 Author Share Posted September 14, 2009 can I do it in the while statement? Quote Link to comment Share on other sites More sharing options...
bigbenbuilders Posted September 14, 2009 Author Share Posted September 14, 2009 friendly bump... I have tried several things to no avail :'( Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 14, 2009 Share Posted September 14, 2009 mysql_num_rows() is used for finding the number of results to a query, not to see if a field is empty. Try if($row['Fieldname'] == '') or if(!preg_match('~[^\s]~',$row['Fieldname'])) Quote Link to comment Share on other sites More sharing options...
bigbenbuilders Posted September 14, 2009 Author Share Posted September 14, 2009 worked great...thanks 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.