Jump to content

if else inside a while


elpaisa

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/87581-if-else-inside-a-while/
Share on other sites

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>';
	   }  
        }	

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.