Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8593311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:57:34+00:00 2026-06-11T23:57:34+00:00

Fatal error: Cannot use string offset as an array in C:\xampp\htdocs\includes\categories\categories.php on line 12

  • 0

Fatal error: Cannot use string offset as an array in
C:\xampp\htdocs\includes\categories\categories.php on line 12

$categories[$parent][] = $row;

categories.php

    <?php

$sql = "SELECT catid, catname, parentid FROM categories";
$res = mysql_query($sql);
while ($row = mysql_fetch_assoc($res)) {
    $parent = intval($row['parentid']);
    if (!isset($categories[$parent])) {
        $categories[$parent] = array();
    }
    $categories[$parent][] = $row;
}
    ?>
    <table border="0" cellpadding="10" cellspacing="0">
    <tr>
        <td valign="top">
    <?php
    $category_string = "";
    function build_categories_options($parent, $categories, $level) {
        global $category_string;
        if (isset($categories[$parent]) && count($categories[$parent])) {
            $level .= " - ";
            foreach ($categories[$parent] as $category) {
                $opt_value = substr($level.$category['catname'],3);
                $category_string .= '<option value=""></option><option value="'.$category['catid'].'">'.$opt_value.'</option>';
                build_categories_options($category['catid'], $categories, $level);
            }
            $level = substr($level, -3);
        }
        return $category_string;
    }
    $category_options = build_categories_options(0, $categories, '');
    $category_options = '<select class="chosen" name="categories" id="categories">'.$category_options.'</select>';
    echo $category_options; 
    ?>
</td>

After I insert post With category This Error Will Show ??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:57:35+00:00Added an answer on June 11, 2026 at 11:57 pm

    I don’t see where $categories is initialized, but I’m betting that it’s not an array when you enter your while loop, and that’s why you’re getting an error. Try doing this for your while loop:

    // initialize $categories to make sure it is an array
    $categories = array();
    while ($row = mysql_fetch_assoc($res)) {
        $parent = intval($row['parentid']);
        $categories[$parent][] = $row;
    }
    

    You don’t need to explicitly initialize $categories[$parent]…this will be done automatically when you call $categories[$parent][] = $row;. We know that it will start out blank because we started with an empty array before the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Fatal error: Cannot use string offset as an array This appears when I try
I'm getting the error: Fatal error: Cannot use object of type stdClass as array
I tend to get errors such as: Fatal error: Cannot redeclare get_raw_data_list() (previously declared
ErrorException [ Fatal Error ]: Class 'Model_Categories' not found MODPATH/orm/classes/kohana/orm.php [ 37 ] 32
I am experiencing a fatal error while using artisan on the (fantastic) Laravel PHP
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 51 bytes)
I'm receiving this fatal error message: Using $this when not in object context. This
I'm getting the error fatal error C9999: *** exception during compilation *** Whenever I
I'm getting the following error: Fatal error: Declaration of Shoppingcart::addToCart() must be compatible with
i encounter an error like Error 1 fatal error LNK1107: invalid or corrupt file:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.