Jump to content

Execute error message if while loop fails


NiTx

Recommended Posts

Hi,

 

I'm trying to execute a while loop which by itself works fine. But I have no idea how to echo an error message if the while loop fails when there is nothing in the database. This is what I've tried so far:

 

if($sel_brand) {
				$device_set = get_devices_by_brand($sel_brand['id']);
				if($device_set) { echo "error"; } else {
				while($devices = mysql_fetch_array($device_set)) {
					echo "<tr><td class=\"video_description\">" . 
					"<a href=\"edit_device.php?device=" . urlencode($devices["id"]) . "\">" .
					"{$devices['dev_model']}" . " " . "{$devices['dev_version']}" . 
					"</a></td></tr>";
				} //end while loop
				}//end if($device_set)
			}//end if($sel_brand)

 

I can see why my code isn't working, but I also know I cant execute my error code in the while loop. I'm really stuck here guys, if you could help that would be great :-)

Sorry my mistake. It's meant to be if(!$device_set) { echo "error"; }

 

This part of the code was a shot in the dark. I didn't think it would work because I should really be testing $devices, but like I said, I can't execute the code inside my while loop. There's probably a really simple solution (I've tried to google it) but I cant figure it out.

 

Essentially I just want to echo an error if there are no devices added in my database for any particular brand.

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.