rbarros Posted January 10, 2011 Share Posted January 10, 2011 Hi, I know the problem that I am having is related to the change in PHP5 about strings and arrays, however I do not understand why my script is affected. It seems like I am not trying to add more variables to an array. I do not success in order solve the problem. Help me please: // Build View Array if ($view_result!=false) { $i=0; while ($view_row =@ mysql_fetch_array($view_result)){ $i++; $view_rows[$i] = $view_row; // build view_comments array if ($viewcomments=="yes") { $sql = "SELECT * FROM blog_comments WHERE nBlogId=".$view_row["nIdCode"]." ORDER BY nIdCode DESC"; $result = mysql_query($sql,$con); if ($result!=false){ $j=0; while ($comment_row =@ mysql_fetch_array($result)){ $j++; $view_comment_rows[$i][$j] = $comment_row; } } } } } else { $problem = "2"; } // increment view counter for either the single blog being shown // or ALL blogs being shown //The problem is here if ($view_rows[1]["nIdCode"]!="" && strpos($_SERVER["PHP_SELF"],"admin.php")==false){ if ($viewmode=="single"){ $blogid = $view_rows[1]["nIdCode"]; $sql = "UPDATE blog SET nViews=nViews+1 WHERE nIdCode=".$blogid; } else { for ($i=1;$i<=count($view_rows);$i++){ $blog_array[$i] = $view_rows[$i]["nIdCode"]; } $blogids = implode(",",$blog_array); $sql = "UPDATE blog SET nViews=nViews+1 WHERE nIdCode IN (".$blogids.")"; } $result = mysql_query($sql,$con); if ($result==false){ print "<li>Problem with SQL<br>[".$sql."]</li>\n"; } } } Last edited by sbarros (2011-01-08 18:21:52) Quote Link to comment https://forums.phpfreaks.com/topic/223964-cannot-use-string-offset-as-an-array/ Share on other sites More sharing options...
salathe Posted January 10, 2011 Share Posted January 10, 2011 Is $view_rows really an array of arrays? Check that it is one (e.g. with var_dump($view_rows)) directly above the line with the problem and tell us what it says. Quote Link to comment https://forums.phpfreaks.com/topic/223964-cannot-use-string-offset-as-an-array/#findComment-1157402 Share on other sites More sharing options...
rbarros Posted January 10, 2011 Author Share Posted January 10, 2011 content var_dump($view_rows)->array(1) { [1]=> array(12) { [0]=> string(2) "42" ["nIdCode"]=> string(2) "42" [1]=> string(19) "2011-01-09 12:00:00" ["dEntryDate"]=> string(19) "2011-01-09 12:00:00" [2]=> string(33) "Cinco anos sem meu filho Décio..." ["cTitle"]=> string(33) "Cinco anos sem meu filho Décio..." [3]=> string(199) " Uma imagem bonita para se guardar como uma marca na alma. Gostava do olhar dele: tinha bondade, uma certa timidez e um jeito de se fazer querer bem..." ["cBody"]=> string(199) " Quote Link to comment https://forums.phpfreaks.com/topic/223964-cannot-use-string-offset-as-an-array/#findComment-1157428 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.