Home > php教程 > php手册 > php实现通用的从数据库表读取数据到数组的函数实例,数组函数

php实现通用的从数据库表读取数据到数组的函数实例,数组函数

WBOY
Release: 2016-06-13 09:10:52
Original
1027 people have browsed it

php实现通用的从数据库表读取数据到数组的函数实例,数组函数

本文实例讲述了php实现通用的从数据库表读取数据到数组的函数。分享给大家供大家参考。具体分析如下:

此函数不关心表结构,只需要指定表名、结构和查询条件既可以对表进行通用查询操作,非常实用。

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

希望本文所述对大家的php程序设计有所帮助。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template