Heim  >  Artikel  >  Backend-Entwicklung  >  php实现通用的从数据库表读取数据到数组的函数实例,数组函数_PHP教程

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

WBOY
WBOYOriginal
2016-07-13 10:02:05733Durchsuche

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

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/970974.htmlTechArticlephp实现通用的从数据库表读取数据到数组的函数实例,数组函数 本文实例讲述了php实现通用的从数据库表读取数据到数组的函数。分享给大...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn