Home > Backend Development > PHP Tutorial > Use function to read the contents of data table into two-dimensional array_PHP tutorial

Use function to read the contents of data table into two-dimensional array_PHP tutorial

WBOY
Release: 2016-07-21 16:04:33
Original
991 people have browsed it

//用函数读出数据表内容放入二维数组
//动态sql语句
//以读出点击次数表为例。

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;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/315937.htmlTechArticle//用函数读出数据表内容放入二维数组 //动态sql语句 //以读出点击次数表为例。 function list_hit($fields,$where,$order,$direction,$limit,$conn) { if ($fiel...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template