elpaisa Posted January 24, 2008 Share Posted January 24, 2008 Hi all! I have a little problem with a while statement, since i have to decide what to show if the query found some positive results or not and echo some code depending of it, this is my code: $getimages = $DB->query("SELECT imageid, title FROM images WHERE activated = 1"); while($images = $DB->fetch_array($getimages)) { $imageid = $images['imageid']; $getmeds = $DB->query("SELECT * FROM meds WHERE pharid = ".$pharid." AND imageid = ".$imageid." "); while($meds = $DB->fetch_array($getmeds)) { if($meds) { echo '<input type="checkbox" name="imageid" id="1" value="'.$images['imageid'].'" '.iif($images['imageid'] == $meds['imageid'], "CHECKED", "").'> <b>'.$images['title'].'</b>'; } else { echo '<input type="checkbox" name="imageid" id="1" value="'.$images['imageid'].'" > <b>'.$images['title'].'</b>'; } } } But this code is not showing any checkbox when no results, so the else statement is not workingl, ??? any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/87581-if-else-inside-a-while/ Share on other sites More sharing options...
The Little Guy Posted January 24, 2008 Share Posted January 24, 2008 that is because $meds will always be ture since there will always be an array when you fetch an array... so... you will need to check for some other value. Quote Link to comment https://forums.phpfreaks.com/topic/87581-if-else-inside-a-while/#findComment-447948 Share on other sites More sharing options...
elpaisa Posted January 24, 2008 Author Share Posted January 24, 2008 well i've tried other options: while($meds = $DB->fetch_array($getmeds)) { if($meds > 0) { echo '<input type="checkbox" name="imageid" id="1" value="'.$images['imageid'].'" '.iif($images['imageid'] == $meds['imageid'], "CHECKED", "").'> <b>'.$images['title'].'</b>'; } elseif($meds == 0) { echo '<input type="checkbox" name="imageid" id="1" value="'.$images['imageid'].'" > <b>'.$images['title'].'</b>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/87581-if-else-inside-a-while/#findComment-447949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.