Jump to content

Need help on if..else statement


FutonGuy

Recommended Posts

Hi

 

I am using the if..else statement to help me to solve some queries.

Here's the code:

 

		
                /////////////////////
	///
	///	LATEST DATA
	///
	/////////////////////

while ($row_export = mysql_fetch_array($result_export, MYSQL_ASSOC))
{	


	/////////////////////////////////
	///
                ///       OPTION 1
	///	DATABASE ON EXISTING TABLE
	///
	/////////////////////////////////

                   $sql_test = "SELECT *
			FROM wsdevice ";

if (trim($pib_bracket_num) !='' and trim($HW_design) !='' )
{				
$sql_test .=" WHERE ((wsdevice_pibid like '%$pib_bracket_num%') and  
                      (device_designid = '$HW_design')) ";	

$results = mysql_query($sql_test) 
	or die ("NO SEARCH TERMS"); 


       while ($row = mysql_fetch_array($results, MYSQL_ASSOC))
             {

	/////////////////////////////////
	///
                ///           OPTION 2
	///	DISPLAY EXISTING DATA IN 
	///          TABLE FORM
	/////////////////////////////////

	/////////////////////////////////
	///
	///	DISPLAY UPDATE ON LATEST DATA
	///              IN TABLE FORM
	/////////////////////////////////

             } 
       } else 
          {

          	/////////////////////////////////
	///
                ///    OPTION 3
	/// DISPLAY LATEST DATA NOT UPDATED
	///         
	/////////////////////////////////

           }
        
}

 

Just wondering if there's any code i can use in order to satisfy the query statement whereby if $sql_test .=" WHERE ((wsdevice_pibid like '%$pib_bracket_num%') and (device_designid = '$HW_design')) "; is true, it will proceed to option 2 and if it doesn't satisfy the query, it will move to option 3 ?

Link to comment
https://forums.phpfreaks.com/topic/202220-need-help-on-ifelse-statement/
Share on other sites

If I understand you correctly.... if query 1 is "true", go to option 2. if query 1 is false, go to option 3?

 

Or: if 1 is false, go to 2. If 2 is false, go to 3?

 

 

(True/False... goes to Option 2/Option 3)

$next_option = 0;

if(condition){
   // condition 1 is true
   $next_option = 2;
}else{
   $next_option = 3;
}


if($next_option == 2){         // or.... if($next_option == 2)
      
     // Code for Option 2. Will only enter this part if condition 1 is "true"
}else{}


if($next_option == 3){
   // Code for option 3. Will enter this part if condition 1 is "false"
}else{}

 

Otherwise, I would use a variable, say $flag = 0;. If a condition is satisfied, set $flag = 1;. Use separate if-then statements to see what the flag value is, and whether or not to enter that loop.

 

 

There's probably an easier way to do this, but just my two cents.

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.