How to use functions to read data table contents into a two-dimensional array in PHP

Source: Internet
Author: User
Reading the contents of a data table with a function into a two-dimensional array
Dynamic SQL statements
Take the read-out number of clicks table for 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 describes how to use the function to read the data table content in PHP into a two-dimensional array, including the reading of the data table aspects, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.