Home > Backend Development > PHP Tutorial > PHP implements a general function example for reading data from a database table into an array, array function_PHP tutorial

PHP implements a general function example for reading data from a database table into an array, array function_PHP tutorial

WBOY
Release: 2016-07-13 10:02:05
Original
776 people have browsed it

PHP implements a general function example for reading data from a database table into an array. Array function

This article describes an example of PHP implementing a general function for reading data from a database table into an array. function. Share it with everyone for your reference. The specific analysis is as follows:

This function does not care about the table structure. It only needs to specify the table name, structure and query conditions to perform general query operations on the table, which is very practical.

function listmytablerows($table, $name, $field, $where, $textID)
{
/ / Connect to the database and query execution
connect ();
$Sql = "select * from". $table. "". $where. "ORDER BY". $field;
$Req = mysql_query($sql);
$Res = mysql_num_rows($req);
?>
<Select name = "<&#63;php echo $name; &#63;>" id="<&#63;php echo $textID; &#63;>">
<option value=""> ____</ option>
<&#63; Php
/ / We do a loop that will read the information for each record
while ($data = mysql_fetch_array($res))
{
  / / We display the information from the current record
&#63;>
   <Option value = "<&#63;php echo $data['id']; &#63;>">
   <&#63;php echo $data[$field]; &#63;>
</ Option>
   <&#63; Php
  }
&#63;>
</ Select>
<&#63; Php
}
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/970974.htmlTechArticlephp implements a general function example for reading data from a database table to an array. The array function example in this article describes the php implementation A general function that reads data from a database table into an array. Share with everyone...
Related labels:
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