Read Data table content with function and put it into two-dimensional array

Source: Internet
Author: User
Use the function to read the data table content into a two-dimensional array dynamic SQL statement to read the number of clicks table as an example. Functionlist_hit ($ fields, $ where, $ order, $ direction, $ limit, $ conn) {if ($ fields & quot;) {$ fields & quot; hit_id, banner_id, hi // read the data table content by using the function and put it into a two-dimensional array
// Dynamic SQL statement
// Take the number of read clicks 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;
}

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.