php - using array for select table in mysql -


i want implement following code via array:

if ($z=='one'){$result = mysql_query( " select * table1", $link);} if ($z=='two'){$result = mysql_query( " select * table2", $link);} 

my try here: (full code)

$z = $_get["z"];  $link = mysql_connect("localhost","root",""); mysql_select_db("dbname",$link);   function one(){ $result = mysql_query( " select * table1"); return $result;  }  function two(){ $result = mysql_query( " select * table2"); return $result;  }  $arr=array ('one'=>"one",'two'=>"two"); $result=$arr[$z]();   while($end = mysql_fetch_assoc($result))    { $end["col1"]; $end["col2"]; $end["col3"];  }  mysql_close($link); 

why code not work ??

tnx friends

$z = $_get["z"];  $link = mysql_connect("localhost","root",""); mysql_select_db("dbname",$link);   function one(){    $result = mysql_query( " select * table1");    return $result; }  function two(){     $result = mysql_query( " select * table2");     return $result; }  $arr=array ('one'=>"one",'two'=>"two"); $result=$arr[$z]();   while($end = mysql_fetch_assoc($result))    {     echo $end["col1"];     echo $end["col2"];     echo $end["col3"]; }  mysql_close($link); 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -