require_once('inc/conn.php');

公司主營業(yè)務(wù):成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)推出伊美免費(fèi)做網(wǎng)站回饋大家。
mysql_query("set names GB2312");
$exec="select * from house_img where 2 ORDER BY Id DESC LIMIT 0, 10";
$result=mysql_query($exec,$conn);
$img=array();
while ($row=mysql_fetch_array($result)) $imd[]=$row['圖片文件的字段名稱'];
mysql_free_result($result);
數(shù)據(jù)庫提到的數(shù)據(jù)一般是資源類型的,要逐一讀出,添加到數(shù)組
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 } ?
$conn=mysql_connect(localhost,root,root) or die("could not connect mysql");
mysql_select_db(數(shù)據(jù)庫,$conn);
$query="SELECT * FROM 表";
$result=mysql_query($query);
while($array=mysql_fetch_array($result)){
arr[]=[$array[1],$array[2]],[$array[2],$array[3]],[$array[3],$array[4]];
}
遍歷數(shù)據(jù)表,把相應(yīng)的數(shù)據(jù)放到數(shù)組中即可
例如:
?php
//定義一個(gè)數(shù)組,用于保存讀取到的數(shù)據(jù)
$contents
=
array();
$query
=
mysql_query("select
*
from
table");
//遍歷數(shù)據(jù)表
while($array
=
mysql_fetch_array($query)){
$contents[]
=
$array;
}
print_r($contents);
//然后循環(huán)數(shù)組,或者通過鍵名使用數(shù)組
foreach($contents
as
$value){
print_r($value);
}
echo
$contents[0]['字段名稱'];
?
直接存數(shù)組里的字符串就行了。
如$a="0,1,2,3,";或$a=join(",",array(0,1,2,3));
mysql_query("INSERT INTO admin (monday) VALUES($a)");
這樣字段monday的就是0,1,2,3,
讀取的時(shí)候要重新組成數(shù)組的話就分割重組。
名稱欄目:php數(shù)據(jù)庫放入數(shù)組,php數(shù)組添加數(shù)據(jù)
標(biāo)題鏈接:http://chinadenli.net/article42/hsjeec.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)站排名、ChatGPT、自適應(yīng)網(wǎng)站、標(biāo)簽優(yōu)化、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)