PHP查詢到的數(shù)據(jù)存放到數(shù)組里面,一般使用$arr[]=$row的方式實(shí)現(xiàn),$row是mysql_fetch_array獲得的一行數(shù)據(jù),本身是一個數(shù)組,執(zhí)行上面的語句之后,這一行會添加存放在額為數(shù)組$arr的最后。
創(chuàng)新互聯(lián)建站主要從事成都網(wǎng)站建設(shè)、成都做網(wǎng)站、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)梁山,十載網(wǎng)站建設(shè)經(jīng)驗(yàn),價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792
典型的例子代碼是這樣的:
mysql_connect('127.0.0.1',?'root',?'123456');
$sql='select?*?from?test.tab';
if?($res=mysql_query($sql)){
while($row=mysql_fetch_array($res))?$result[]=$row;
mysql_free_resule($res);
}else?echo?"執(zhí)行SQL語句:$sqlbr\n錯誤:".mysql_error();
echo?'查詢結(jié)果在下面的額為數(shù)組里面:pre';
print_r($result);
echo?'/pre';
看你是怎么連接數(shù)據(jù)庫的了,
mysqli好像有直接獲取所有結(jié)果的函數(shù),
要是一次一次的獲取的,
可以使用array_push來講結(jié)果壓到一個數(shù)組當(dāng)中。
input的name用數(shù)組,比如:
tr
tdinput type="text" name="name1[]"/td
tdinput type="text" name="name2[]"/td
/tr
tr
tdinput type="text" name="name1[]"/td
tdinput type="text" name="name2[]"/td
/tr
tr
tdinput type="text" name="name1[]"/td
tdinput type="text" name="name2[]"/td
/tr
提交后$_POST['name1']、$_POST['name2']都會以數(shù)組的方式儲存著3行tr的每個值,通過foreach可以把它們逐行添加進(jìn)數(shù)據(jù)表
思路:
先讀出來再寫進(jìn)去
具體的話,看你使用什么操作數(shù)據(jù)庫,php自帶的有PDO,像thinkphp之類的框架有自己實(shí)現(xiàn)的查詢構(gòu)造器操作數(shù)據(jù)庫
你還是用循環(huán)吧。
$arr=explode("|||",$reply);
$query="insert
into
{$cfg_dbprefix}askanswer
(askid,
ifanswer,
tid,
tid2,
uid,
username,
anonymous,
userip,
brief,
dateline,
content,
ifcheck)
";
//循環(huán)構(gòu)造sql語句
foreach($arr
as
$v)
{
$sql.=",values('$askid',
'1',
'$tid',
'$tid2',
'$uid',
'$username',
'$anonymous',
'$userip',
'$brief',
'$timestamp',
'$v',
'0')";
}
//去掉第一個‘,’號
$sql=$query.substr($sql,1);
//插入語句
$dsql-ExecuteNoneQuery($sql);
到這就可以了。
當(dāng)前題目:php數(shù)據(jù)庫多條數(shù)據(jù)存儲,php數(shù)據(jù)庫多條數(shù)據(jù)存儲不同
地址分享:http://sd-ha.com/article2/dsiphoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、App設(shè)計(jì)、動態(tài)網(wǎng)站、定制開發(fā)、網(wǎng)站維護(hù)、網(wǎng)站收錄
聲明:本網(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)