Re: [SMARTY] Array problem

From: Date: Sat, 23 Nov 2002 20:14:51 +0000
Subject: Re: [SMARTY] Array problem
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6531@lists.php.net to get a copy of this message
At 21:00 2002-11-23 +0100, you wrote:
At 20:46 2002-11-23 +0100, you wrote:
On 23 Nov 2002 at 20:21, Michael Paluchowski wrote:
Now why doesn't this work? $smart = 'array("FirstName" => "Ned","LastName" => "Flanders"),
                              array("FirstName" => "Monty","LastName" 
=> "Burns")';
Look at your single quotes around array(); You are defining a string, not an array!
OK, did it :) Thanks for the help! Damn, still not working like it should... Seems that I'll have to do some more explanations here. The whole thing looks like this: I've got a list of categories in a table in the database. Every category has it's own ID, a parent category ID (if it's the top level category, that ID's value is zero) and a name. This all gets selected, and made an array, in which every row has data from one category. Now in a loop every row of the array gets checked, those which contain top level categories, are put into a smarty array $MainCategory, and all the others into the smarty array $SubCategory. The code looks like this: $sql = 'SELECT *
                FROM ' . ARTICLES_CATEGORIES_TABLE;
$result = $db->Execute ($sql); if ($result === false) die ("failed"); $all_categories = $result->GetArray(); $total_categories = $result->RecordCount(); $menu_index = 0; $main_category_array = ''; $sub_category_array = ''; for ($i = 0; $i < $total_categories; $i++) {
        $category_id = $i + 1;
        $category_name = $all_categories[$i]['artcat_name'];
        if ($all_categories[$i]['parent_id'] == 0)
        {
                $main_category_array = $main_category_array . 'array("CategoryID" => "' . $category_id . '", "MenuIndex" => "' . $menu_index . '", "MainName" => "' . $category_name . '"), ';
                $menu_index++;
        }
        else
        {
                $parent_id = $all_categories[$i]['parent_id'];
                $sub_category_array = $sub_category_array . 'array("CategoryID" => "' . $category_id . '", "ParentID" => "' . $parent_id . '", "CategoryName" => "' . $category_name . '"), ';
        }
} $main_category_array = substr ($main_category_array, 0, strlen($main_category_array) - 2); $sub_category_array = substr ($sub_category_array, 0, strlen($sub_category_array) - 2); $smarty->assign(array("MainCategory" => array($main_category_array))); $smarty->assign(array("SubCategory" => array($sub_category_array))); Don't worry about the database part or other conversions. The only problem is in creating a smarty array. Mike

« previous php.smarty.general (#6531) next »