數(shù)據(jù)庫提到的數(shù)據(jù)一般是資源類型的,要逐一讀出,添加到數(shù)組
創(chuàng)新互聯(lián)建站為您提適合企業(yè)的網(wǎng)站設(shè)計(jì)?讓您的網(wǎng)站在搜索引擎具有高度排名,讓您的網(wǎng)站具備超強(qiáng)的網(wǎng)絡(luò)競爭力!結(jié)合企業(yè)自身,進(jìn)行網(wǎng)站設(shè)計(jì)及把握,最后結(jié)合企業(yè)文化和具體宗旨等,才能創(chuàng)作出一份性化解決方案。從網(wǎng)站策劃到成都做網(wǎng)站、成都網(wǎng)站建設(shè), 我們的網(wǎng)頁設(shè)計(jì)師為您提供的解決方案。
while($row = mysql_fetch_assoc($res)){
$data[] = $row;
}
本文實(shí)例講述了php實(shí)現(xiàn)通用的從數(shù)據(jù)庫表讀取數(shù)據(jù)到數(shù)組的函數(shù)。分享給大家供大家參考。具體分析如下:
此函數(shù)不關(guān)心表結(jié)構(gòu),只需要指定表名、結(jié)構(gòu)和查詢條件既可以對表進(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 } ?
php查詢mysql數(shù)據(jù)庫并將結(jié)果保存到數(shù)組的方法。具體分析如下:
主要用到了mysql_fetch_assoc函數(shù)
mysql_fetch_assoc語法如下:
?
1
array mysql_fetch_assoc (resource $Result_Set)
范例代碼如下:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
?php
$UserName = 'abc';
$Password = '1234';
$DbHandle = mysql_connect ('localhost', $UserName, $Password);
if (!$DbHandle) {
die 'No database connection could be established.';
}
$DBName = 'w3db;
if (!mysql_select_db ($DBName, $DbHandle)) {
die 'Database could not be selected.';
}
$Query = "SELECT ISBN, Title, Author FROM articles";
$articles = mysql_query ($Query, $DbHandle));
while ($Row = mysql_fetch_assoc ($articles)) {
echo "ISBN = $Row['ISBN']br /\n";
echo "Title = $Row['Title']br /\n";
echo "Author = $Row['Author']br /\n";
}
?
名稱欄目:php數(shù)據(jù)庫到數(shù)組 php傳數(shù)組
當(dāng)前網(wǎng)址:http://vcdvsql.cn/article4/dopesoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、企業(yè)建站、手機(jī)網(wǎng)站建設(shè)、域名注冊、、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)