Hi there I follow tutorial from this site : www.phpwebcommerce.com. For the original coding from the tutorial 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.
For the script i add on, i’m using “” instead of “echo $categoryList;” this method works but it need to manually put in option value in every product.php page instead of auto.
For the original script, it should works like, admin go to add category (eg: category name ABC), then admin go to add product , admin select category (eg:ABC) then save, DONE.
For the script i edited, admin go to add category (eg: category name ABC), then admin go to add product, admin couldn’t find category name ABC, to make it works,i need manually go product/add.php enter ABC and let admin select category list.
i guess the problem is at:
function.php
- function buildCategoryOptions & build combo box options
or
add.php
i also attacth a javascript “category.js” i’m not sure is there any error for the file.
function.php
[php]
/*
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;
}
[/php]
product/add.php
[php]
Add Product | |
Category |
|
Product Name | |
Description | |
Price | |
Qty In Stock | |
Image |
[/php]
category.js
// JavaScript Document
function checkCategoryForm()
{
with (window.document.frmCategory) {
if (isEmpty(txtName, 'Enter category name')) {
return;
} else if (isEmpty(mtxDescription, 'Enter category description')) {
return;
} else {
submit();
}
}
}
function addCategory(parentId)
{
targetUrl = 'index.php?view=add';
if (parentId != 0) {
targetUrl += '&parentId=' + parentId;
}
window.location.href = targetUrl;
}
function modifyCategory(catId)
{
window.location.href = 'index.php?view=modify&catId=' + catId;
}
function deleteCategory(catId)
{
if (confirm('Deleting category will also delete all products in it.\nContinue anyway?')) {
window.location.href = 'processCategory.php?action=delete&catId=' + catId;
}
}
function deleteImage(catId)
{
if (confirm('Delete this image?')) {
window.location.href = 'processCategory.php?action=deleteImage&catId=' + catId;
}
}
Thank you so much, any help will appreciate