Jump to content

[SOLVED] Get field for all entries in table, but breaks when 0 entries. How to fix?


physaux

Recommended Posts

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.