Home >Backend Development >PHP Tutorial >Data table Use function to read the contents of the data table into a two-dimensional array
//Use a function to read the contents of the data table and put it into a two-dimensional array
//Dynamic sql statement
//Take reading the number of clicks table as an example.
function list_hit($fields,$where,$order,$direction,$limit,$conn)
{
if ($fields=="") {$fields="hit_id,banner_id,hit_ip,hit_time";}
if ($order=="") {$direction="";}
$sql="select $fields from hit $where $order $direction $limit";
//echo $sql;
$res=mysql_query( $sql,$conn);
$i=0;
$list_hit[$i]["rows"]=mysql_num_rows($res);
$i++;
while($rs=mysql_fetch_array($res))
{
$list_hit[$i]["hit_id"]=$rs["hit_id"];
$list_hit[$i]["banner_id"]=$rs["banner_id"];
$list_hit[$i][ "hit_ip"]=$rs["hit_ip"];
$list_hit[$i]["hit_time"]=$rs["hit_time"];
$i++;
}
return $list_hit;
}
The above introduces the use of functions to read out the contents of the data table and put it into a two-dimensional array, including the content of the data table. I hope it will be helpful to friends who are interested in PHP tutorials.