我从数据库中获取信息,将其保存在数组中并以循环结构的形式回显它,当我尝试将修改后的信息保存到数据库时,我遇到了问题.
我收到此错误:致命错误:[]运算符不支持....
码:
$namesql1 = "SELECT name,date,text,date2 FROM table WHERE something= '$something'";
$nameresult1 = mysql_query($namesql1);
$countrows = mysql_num_rows($nameresult1);
while ($row = mysql_fetch_array($nameresult1, MYSQL_ASSOC)) {
$name[] = $row['name'];
$date[] = $row['date'];
$text[] = $row['text'];
$date2[] = $row['date2 '];
}
/** SOME CODE HERE **/
$wrotesql = "UPDATE service_report SET name ='$name' , $date = '$date',$text = '$text[$nro]', ser_date = '$date2[$nro]' WHERE something = '$something')";
$wroteresult = mysql_query($wrotesql);
Run Code Online (Sandbox Code Playgroud)
有人可以给我一个暗示我做错了吗?
谢谢.
我写了(感谢Stackoverflow帮助)一个PHP脚本(称为wunder_temp.php),它显示给定数量的Weatherunderground.com站的温度和位置.
我将这个脚本包含在我的页脚中,它在单个页面上运行良好.如果我打开http://www.flapane.com/guestbook/guestbook.php,我的页脚将不显示温度,error.log说:[09-Sep-2012 09:46:45 UTC] PHP致命错误:第47行/home/xxx/public_html/wunder_temp.php中的字符串不支持[]运算符
$display = file($cachename, FILE_IGNORE_NEW_LINES); //ignore \n for non-reporting stations
foreach ($display as $key=>$value){
if($key % 2 == 0){
$temperature[] = $value; // EVEN (righe del file cache pari)
}else{
$location[] = $value; // ODD - **HERE IS LINE 47**
}
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是,guestbook.php是我网站的唯一页面,其中wunder_temp.php不起作用.
上面的代码所做的是读取缓存文件并在$ temperature []数组中输入偶数行,在$ location []数组中输入奇数行.这是我的缓存文件中的一个示例:
26.8
Stadio San Paolo di Napoli, Napoli
24.4
Pozzuoli
Run Code Online (Sandbox Code Playgroud)
老实说,我不知道为什么我在留言簿页面上看到了这些错误.
事实证明,"罪魁祸首"是函数loadmore.php,它使用twitter风格的ajax函数加载留言簿评论(并包含在guestbook.php中).如果我不包含它,wunder_temp.php运行良好,并且不会产生任何错误.
loadmore.php:
<div id='contcomment'>
<div class="timeline" id="updates">
<?php
$sql=mysql_query("select * from gbook_comments ORDER BY id DESC …Run Code Online (Sandbox Code Playgroud)