Jump to content

Cannot use string offset as an array


rbarros

Recommended Posts

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)

 

Link to comment
https://forums.phpfreaks.com/topic/223964-cannot-use-string-offset-as-an-array/
Share on other sites

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) "

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.