Jump to content

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

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.