Thread: Search Upgrade
View Single Post
  #18  
Old 07-25-2003, 12:46 PM
 
Cameron Cameron is offline
 

eXpert
  
Join Date: Jan 2003
Location: Washington State, USA
Posts: 224
 

Default Looking for code clarity

Even though I did understand "funky's loop" I'm not getting this search mod to work.

To my categories.php file I added before the # Assign Smarty variables this code:
Quote:
#
# Mod: Get all main categories and level 1 subcatgories and store them in an array
#
$categories_data1 = func_query("select * from $sql_tbl[categories] where category NOT LIKE '%/%' and avail='Y' group by $sql_tbl[categories].categoryid order by order_by");

foreach ($categories_data1 as $key=>$value) {
$categories_data2[$key][] = func_query("select $sql_tbl[categories].*, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', -1) as category_name from $sql_tbl[categories] where category LIKE '".$value[category]."/%' and category NOT LIKE '".$value[category]."/%/%' and avail='Y' group by $sql_tbl[categories].categoryid order by order_by");
$categories_data2[$key][category] = strrchr($categories_data2[$key][category], "/");
}
...which I took from two of machnhed1's posts. I think that part is correct. In my advanced_search.tpl I replaced the lines
Quote:
<select name="in_category">
<option value="">All</option>
{section name=cat_num loop=$categories}
<option value="{ $categories[cat_num].categoryid}" {if $smarty.get.in_category eq $categories[cat_num].categoryid or $cat eq $categories[cat_num].categoryid}selected{/if}>{$categories[cat_num].category|escape}</option>
{/section}
</select>
with this:
Quote:
<select name="in_category">
<option value="">All</option>
{section name=cat_num loop=$categories_level_1}
<option value="{ $categories_level_1[cat_num].categoryid}" {if $smarty.get.in_category eq $categories_level_1[cat_num].categoryid or $cat eq $categories_level_1[cat_num].categoryid}selected{/if}>
{$categories_level_1[cat_num].category|escape}
</option>

{section name=cat_num1 loop=$categories_level_2}
{if $categories_level_2[cat_num][0][cat_num1].categoryid ne ""}<option value="{ $categories_level_2[cat_num][0][cat_num1].categoryid}" {if $smarty.get.in_category eq $categories_level_2[cat_num][0][cat_num1].categoryid or $cat eq $categories_level_2[cat_num][0][cat_num1].categoryid}selected{/if}>
{$categories_level_2[cat_num][0][cat_num1].category|escape}
</option>{/if}
{/section}

{/section}
</select>
But what happens is that in advanced search, the categories list doesn't have any options in it. I saw that funky advised putting in this code: {$categories_level_2[cat_num][0][cat_num1].category_name|escape} but I'm not sure exactly where to put that in. I tried replacing
{ $categories_level_2[cat_num][0][cat_num1].categoryid}
with funky's line, but I still get the same results.

Can one of the wizards out there post the code I should use?

Thanks
Cameron
Reply With Quote