php查詢mysql數(shù)據(jù)庫并將結(jié)果保存到數(shù)組的方法。具體分析如下:
成都創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站建設、成都網(wǎng)站設計、網(wǎng)頁設計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務。立足成都服務渾源,十多年網(wǎng)站建設經(jīng)驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:18982081108
主要用到了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
$arr = array();
$query = mysql_query($sql);
while($row=mysql_fetch_assoc($query))
{
$arr[]=$row;
}
?
此時 $arr 應該是一個二維數(shù)組
假如 數(shù)據(jù)為 $value
$temp=explode(",",$value);?
foreach($temp?as?$v){
$result[$v]=1;
}
然后html的時候可以這樣:
if($result['admin']){
echo?'input?type=checkbox?/';
}
同理其他類型,可以foreach?輸出