array2string函數(shù) 是phpcms自帶的函數(shù)
專注于為中小企業(yè)提供網(wǎng)站設(shè)計(jì)制作、網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)平羅免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上1000家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
/phpcms/libs/functions/global.func.php 第293行
/**
* 將數(shù)組轉(zhuǎn)換為字符串
*
* @param array $data 數(shù)組
* @param bool $isformdata 如果為0,則不使用new_stripslashes處理,可選參數(shù),默認(rèn)為1
* @return string 返回字符串,如果,data為空,則返回空
*/
function array2string($data, $isformdata = 1) {
if ($data == '')
return '';
if ($isformdata)
$data = new_stripslashes($data);
return addslashes(var_export($data, TRUE));
}
php查詢mysql數(shù)據(jù)庫(kù)并將結(jié)果保存到數(shù)組的方法。具體分析如下:
主要用到了mysql_fetch_assoc函數(shù)
mysql_fetch_assoc語(yǔ)法如下:
?
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";
}
?
數(shù)據(jù)庫(kù)提到的數(shù)據(jù)一般是資源類型的,要逐一讀出,添加到數(shù)組
while($row = mysql_fetch_assoc($res)){
$data[] = $row;
}
lxydjx 正解,我來(lái)詳細(xì)補(bǔ)充一下吧。未經(jīng)測(cè)試、、、
//初始化
$sql = array();
// 從 a.php POST 過(guò)來(lái)的值
$_POST["xinxi"] = "20-2,19-1,18-1";
// 拆分為 array("20-2", "19-1", "18-1");
$post_data = explode(",", $_POST["xinxi"]);
// 循環(huán)數(shù)組
for($i = 0; $i count($post_data); $i++) {
// 再次拆分每一條信息為 array("20", "2"), array("19", "1"), array("18", "1")
$details = explode("-", $post_data[$i]);
// 將每一條信息添加到 $sql 數(shù)組中
array_push($sql, "(20121015194535193356, ".$details[0].", ".$details[1].")");
}
// 用 , 連接,轉(zhuǎn)換為 string
$sql = implode(",", $sql);
// 插入數(shù)據(jù)庫(kù)
mysql_query("INSERT INTO table_sales (dingid, detailsid, buynumber) VALUES ($sql)");
網(wǎng)頁(yè)名稱:php數(shù)據(jù)庫(kù)配置數(shù)組 php怎么配置數(shù)據(jù)庫(kù)
鏈接URL:http://muchs.cn/article34/doedgpe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、小程序開(kāi)發(fā)、外貿(mào)建站、商城網(wǎng)站、做網(wǎng)站、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)