Home  >  Article  >  Backend Development  >  How to use a function to read the contents of a data table into a two-dimensional array in PHP

How to use a function to read the contents of a data table into a two-dimensional array in PHP

WBOY
WBOYOriginal
2016-08-08 09:33:521219browse

//Use a function to read the contents of the data table and put it into a two-dimensional array
//Dynamic sql statement
//Take reading out the click count 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 how to use functions to read the contents of a data table into a two-dimensional array in PHP, including the content of reading a data table. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn