Question

I am trying to create a query from the data i receive from an array of objects in php. I keep receiving an error on the nested if inside a case. unexpected '{', is it because I can't have an if within a case?

switch($name){ 
case 'players': 
      $query .= " min_players <=".$value." AND max_players >=".$value." AND"; 
      break; 
case 'max-duration':         
      if((intval($value) >= 45)  {  
          $min = intval($value)-30;  
          $query .= " duration <=".$value." AND duration >=".$min." AND"; 
      } else { //if duration < 45  
            $query .= " duration <=".$value." AND";  
      }//end else 
      break; 
}
Was it helpful?

Solution

switch($name){ 
case 'players': 
      $query .= " min_players <=".$value." AND max_players >=".$value." AND"; 
      break; 
case 'max-duration':         
      if((intval($value)) >= 45)  {  
          $min = intval($value)-30;  
          $query .= " duration <=".$value." AND duration >=".$min." AND"; 
      } else { //if duration < 45  
            $query .= " duration <=".$value." AND";  
      }//end else 
      break; 
}

You had to add a ) after if((intval($value)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top