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
Post a Comment