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 :-)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.