Jump to content

[SOLVED] IF... Else


june_c21

Recommended Posts

hi, can someone help me to figure out what's wrong with this code. thanks

 

$query = "SELECT unit FROM report " ;

$result = mysql_query($query,$dblink);

while($row = mysql_fetch_array($result))

  {

$unit = $row[0];

}

 

if($unit==GF1)

  {

  // echo "this is Role #1"

  $redirect = 'sort_gf1.php' ;

  }

  elseif($unit==2)

  {

  $redirect = 'champ.html';

  }

  elseif($unit==3)

  {

  $redirect = 'champ.html';

  }

  else

  {

  $redirect = 'view1.php';

  }

header ("Location: $redirect");

Link to comment
https://forums.phpfreaks.com/topic/82141-solved-if-else/
Share on other sites

You can try with switch too...

 

<?php
$query = "SELECT unit FROM report " ;
$result = mysql_query($query,$dblink);
while($row = mysql_fetch_array($result))
{
$unit = $row[0];
}

switch ($unit) 
{
  case "GF1":
  header ("Location: sort_gf1.php");
  break;
  
  case "2":
  header ("Location: champ.html");
  break;

  case "3":
  header ("Location: champ.html");
  break;
  
  default:
  header ("view1.php");
  break;
}


?>

Link to comment
https://forums.phpfreaks.com/topic/82141-solved-if-else/#findComment-417417
Share on other sites

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.