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. ?> Link to comment https://forums.phpfreaks.com/topic/174185-solved-if-database-field-empty-display-na/ 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? Link to comment https://forums.phpfreaks.com/topic/174185-solved-if-database-field-empty-display-na/#findComment-918249 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 :'( Link to comment https://forums.phpfreaks.com/topic/174185-solved-if-database-field-empty-display-na/#findComment-918268 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'])) Link to comment https://forums.phpfreaks.com/topic/174185-solved-if-database-field-empty-display-na/#findComment-918269 Share on other sites More sharing options...
bigbenbuilders Posted September 14, 2009 Author Share Posted September 14, 2009 worked great...thanks Link to comment https://forums.phpfreaks.com/topic/174185-solved-if-database-field-empty-display-na/#findComment-918271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.