physaux Posted November 4, 2009 Share Posted November 4, 2009 <?php $result = mysql_query("SELECT * FROM `MY_FIELD` WHERE field = `".$fieldname."`;", $connection); if (!$result) { echo "Database query failed: " . mysql_error();// } ?> So, my code want to check in the "MY_FIELD", and get all the entries there. I made this code, but It seems to fail. The table has no entries, yet. So I was wondering, how can I "error proof" it so it acts nicely if the table is empty? Right now prints out: Database query failed: Unknown column 'main_name' in 'where clause' *"main_name"* is the current value of $fieldname right now. This is the current "name" that I would be looking for, but the table is empty. Link to comment https://forums.phpfreaks.com/topic/180335-solved-get-field-for-all-entries-in-table-but-breaks-when-0-entries-how-to-fix/ Share on other sites More sharing options...
mrMarcus Posted November 4, 2009 Share Posted November 4, 2009 "acts nicely", how? what do you want it to do? Link to comment https://forums.phpfreaks.com/topic/180335-solved-get-field-for-all-entries-in-table-but-breaks-when-0-entries-how-to-fix/#findComment-951313 Share on other sites More sharing options...
physaux Posted November 4, 2009 Author Share Posted November 4, 2009 Well, first off I want to be able to detect that there are no entries, then not continue with the regular script since it crashes. So, my question rephrased is: How can I detect if a table is empty? Link to comment https://forums.phpfreaks.com/topic/180335-solved-get-field-for-all-entries-in-table-but-breaks-when-0-entries-how-to-fix/#findComment-951319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.