本文实例讲述了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 = "<?php echo $name; ?>" id="<?php echo $textid; ?>">
<option value=""> ____</ option>
<? 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
?>
<option value = "<?php echo $data['id']; ?>">
<?php echo $data[$field]; ?>
</ option>
<? php
}
?>
</ select>
<? php
}
?>
希望本文所述对大家的php程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!