Here is the code in the php file
//calculate how many products are there in the root category
$q = db_query("SELECT count(*) FROM ".PRODUCTS_TABLE." WHERE categoryID=0") or die (db_error());
$cnt = db_fetch_row($q);
$smarty->assign("products_in_root_category",$cnt[0]);
//create a category tree
$c = fillTheCList(0,0);
$smarty->assign("categories", $c);
//show category name as a title
$row = array();
if (!isset($_GET["categoryID"]) && !isset($_POST["categoryID"]))
{
$categoryID = 0;
$row[0] = ADMIN_CATEGORY_ROOT;
}
else //go to the root if category doesn't exist
{
$categoryID = isset($_GET["categoryID"]) ? $_GET["categoryID"] : $_POST["categoryID"];
$q = db_query("SELECT name FROM ".CATEGORIES_TABLE." WHERE categoryID<>0 and categoryID='$categoryID'") or die (db_error());
$myFile = "dunx.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "SELECT name FROM ".CATEGORIES_TABLE." WHERE categoryID<>0 and categoryID='$categoryID'";
fwrite($fh, $stringData);
fclose($fh);
$row = db_fetch_row($q);
if (!$row)
{
$categoryID = 0;
$row[0] = ADMIN_CATEGORY_ROOT;
}
}
$smarty->assign("categoryID", $categoryID);
$smarty->assign("category_name", $row[0]);
//get all products
$q = db_query("SELECT productID, name, customers_rating, Price, in_stock, picture, big_picture, thumbnail, items_sold, enabled, product_code FROM ".PRODUCTS_TABLE." WHERE categoryID='$categoryID' ORDER BY name;") or die (db_error());
$result = array();
$num = mysql_num_rows($q);
$i=0;
while ($row = db_fetch_row($q)) $result[$i++] = $row;
//update result
for ($i=0; $i<count($result); $i++)
{
if (!trim($result[$i][5]) || !file_exists("./products_pictures/".trim($result[$i][5])))
$result[$i][5] = "";
if (!trim($result[$i][6]) || !file_exists("./products_pictures/".trim($result[$i][6])))
$result[$i][6] = "";
if (!trim($result[$i][7]) || !file_exists("./products_pictures/".trim($result[$i][7])))
$result[$i][7] = "";
}
//products list
$smarty->assign("products", $result);
$smarty->assign("products_count", $num);
//set main template
$smarty->assign("admin_sub_dpt", "catalog_products_categories.tpl.html");
}
Then in the template this is what calls the variable :
{* categories *}
<tr>
<td valign="top" bgcolor="#E2E2FF" width="25%">
<table width="100%" border="0">
<tr>
<td colspan=3><a href="admin.php?dpt=catalog&sub=products_categories&categoryID=0" style="font-weight: bold;">{$smarty.const.ADMIN_CATEGORY_ROOT}</a> ({$products_in_root_category})</td>
</tr>
{section name=i loop=$categories}
<tr>
<td>{section name=j loop=$categories[i][5] max=$categories[i][5]} {/section}<a href="admin.php?dpt=catalog&sub=products_categories&categoryID={$categories[i][0]}"{if $categories[i][5] eq 0} style="font-weight: bold;"{/if}>{$categories[i][1]}</a></td>
<td>({$products_count})</td>
<td align="right"><font color="red">[</font><a class="small" href="javascript:open_window('category.php?c_id={$categories[i][0]}&w={$categories[i][4]}',400,400);">edit</a><font color=red>]</font></td>
</tr>
{/section}
</table>
<br><center>[ <a href="javascript:open_window('category.php?w=-1',400,400);">{$smarty.const.ADD_BUTTON}</a> ]</center><br>
</td>
any help is appreciated...
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.