php - nested if loop partially working -


what trying display row values. suppose if field 'head_office' dont have value 'h.o' want display values of last row. tried cant find solution. here code: (i have blocked php part)

 <?php  $mysql_host = 'localhost';  $mysql_user = 'root';  $mysql_password = '123';  $mysql_database = 'sdbms';  $setup_page = './myinstitute.php';  $db = mysql_connect($mysql_host, $mysql_user, $mysql_password);  mysql_select_db($mysql_database, $db);    if(isset($_request['id'])){     $id=$_request['id'];     $sql = "select * institute id =$id";     $result = mysql_query($sql, $db);     $row = mysql_fetch_array($result);  }  else if(!isset($_request['id'])){     $sql = 'select * institute head_office ="h.o"';     $result = mysql_query($sql, $db);     $row = mysql_fetch_array($result);  }  else{     $sql="select * institute";     $result = mysql_query($sql, $db);     $n = mysql_num_rows($result); //counting number of rows     if($n==0){         header('location: '.$setup_page);     }     else{         $sql = 'select * institute order id desc limit 1';         $result = mysql_query($sql, $db);         $row = mysql_fetch_array($result);     }  }  ?> 

i don't understand how want do, it's illogic: 3 step don't execute ever. try it:

if(isset($_request['id'])){     $id=$_request['id'];     $sql = "select * institute id =$id";     $result = mysql_query($sql, $db);     $row = mysql_fetch_array($result); } else if(!isset($_request['id'])){     $sql = 'select * institute head_office ="h.o"';     $result = mysql_query($sql, $db);     $row = mysql_fetch_array($result); } if(count($row)<=0) {     $sql="select * institute";     $result = mysql_query($sql, $db);     $n = mysql_num_rows($result); //counting number of rows     if($n==0){         header('location: '.$setup_page);     }     else{         $sql = 'select * institute order id desc limit 1';         $result = mysql_query($sql, $db);         $row = mysql_fetch_array($result);     } } 

enjoy code.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -