我使用下面的腳本進行追加的序列化陣列無法訪問數據庫,PHP
mysql_select_db("formdemo", $con);
$result=mysql_query("select * from rohit where fid='$y'");
if(mysql_num_rows($result)!=0)
{
if($result)
{
while($row=mysql_fetch_array($result))
{
$n=$row['tags'];
$a=explode(',', $n);
print_r($a);
$cnt=count($a);
$x=unserialize($row['data']);
for($i=0;$i<$cnt;$i++)
{
$d=$_GET[$a[$i]];
array_push($x,$d);
}
array_push($x,"<br/>");
}
}
}
$str=serialize($x);
$sql="update rohit set data='$str' where fid='$y'";
if(!mysql_query($sql,$con))
die(mysql_error());
else
echo "Your data has been updated successfully\n";
當我在第一次運行這個當數據庫爲空,則給了一個錯誤: array_push ()期望參數1爲數組, 並在數據庫中存儲值b; 0。在這種情況下我該怎麼做。請幫助...
什麼是'$ d'?你試圖把'$ d'推到'$ x'上,但'$ x'是一個字符串 – JamesHalsall 2012-07-13 13:05:39
是的,所以問題是什麼 – 2012-07-13 13:06:50
'$ d'是什麼意思? – JamesHalsall 2012-07-13 13:07:41