Jump to content

select category phpwebcommerce help !


desmond_ckl

Recommended Posts

Hi there,I'm new to php...i'm following a tutorial from this site http://www.phpwebcommerce.com/index.php  I just want to learn it & set up a simple store from this tutorial. My problem is, in the admin section when I try to add a new product the combo box doesn't allow me to select the category. It is listing the category, but it isn't allowing me to select it, if i cant select the category the whole product page won't be save.

 

Below is the code:

/* 
    Generate combo box options containing the categories we have. 
    if $catId is set then that category is selected 
*/ 
function buildCategoryOptions($catId = 0) 
{ 
    $sql = "SELECT cat_id, cat_parent_id, cat_name 
            FROM tbl_category 
            ORDER BY cat_id"; 
    $result = dbQuery($sql) or die('Cannot get Product. ' . mysql_error()); 
     
    $categories = array(); 
    while($row = dbFetchArray($result)) { 
        list($id, $parentId, $name) = $row; 
         
        if ($parentId == 0) { 
            // we create a new array for each top level categories 
            $categories[$id] = array('name' => $name, 'children' => array()); 
        } else { 
            // the child categories are put int the parent category's array 
            $categories[$parentId]['children'][] = array('id' => $id, 'name' => $name);     
        } 
    }     
     
    // build combo box options 
    $list = ''; 
    foreach ($categories as $key => $value) { 
        $name     = $value['name']; 
        $children = $value['children']; 
         
        $list .= "<optgroup label=\"$name\">";  
         
        foreach ($children as $child) { 
            $list .= "<option value=\"{$child['id']}\""; 
            if ($child['id'] == $catId) { 
                $list.= " selected"; 
            } 
             
            $list .= ">{$child['name']}</option>\r\n"; 
        } 
         
        $list .= "</optgroup>"; 
    } 
     
    return $list; 
}  

 

Thank you in advance.  ;)

Link to comment
https://forums.phpfreaks.com/topic/242604-select-category-phpwebcommerce-help/
Share on other sites

It maybe because it's pretty early but the first thing I can think of is that

the part that  is marked as a label for the <optgroup> can't be selected. only the children of that label can.

for istance:

 

<select>
  <optgroup label="Cold Drinks">  <!---- is non selectable -->
    <option value="Soda">Soda</option>
    <option value="Cola">Cola</option>
  </optgroup>
  <optgroup label="Hot Drinks">  <!---- is non selectable -->
    <option value="Tea">Tea</option>
    <option value="Coffee">Coffee</option>
  </optgroup>
</select>

 

The script you gave creates a main category as far as i saw it and marks it as a label with children that can be selected.

 

Is this maybe what you are experiencing?

  • 3 weeks later...

Thanks for helping cssfreakie, but this method can only select subcategory.....and even the subcategory can be select , when i click on save....it show errors .

 

anyone know how to solve this problem ?

i have been searching books & google..... still cant solve it. :'(

 

any help will appreciate  :-*

 

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.