php實(shí)現(xiàn)通用的從數(shù)據(jù)庫表讀取數(shù)據(jù)到數(shù)組的函數(shù)實(shí)例
本文實(shí)例講述了php實(shí)現(xiàn)通用的從數(shù)據(jù)庫表讀取數(shù)據(jù)到數(shù)組的函數(shù)。分享給大家供大家參考。具體分析如下:
此函數(shù)不關(guān)心表結(jié)構(gòu),只需要指定表名、結(jié)構(gòu)和查詢條件既可以對(duì)表進(jìn)行通用查詢操作,非常實(shí)用。
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
}
?>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
php empty()與isset()區(qū)別的詳細(xì)介紹
本篇文章是對(duì)php中empty()與isset()的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
推薦Discuz!5的PHP代碼高亮顯示與實(shí)現(xiàn)可運(yùn)行代碼
推薦Discuz!5的PHP代碼高亮顯示與實(shí)現(xiàn)可運(yùn)行代碼...2007-03-03
PHP截取漢字亂碼問題解決方法mb_substr函數(shù)的應(yīng)用
利用mb_substr截取字符串不會(huì)出現(xiàn)亂碼問題,高手可以飛過......2008-03-03
PHP簡單實(shí)現(xiàn)二維數(shù)組的矩陣轉(zhuǎn)置操作示例
php常用字符串輸出方法分析(echo,print,printf及sprintf)

