Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question


Avatar of John Account
John Account asked on
8 Comments1 Solution589 ViewsLast Modified:
I am using a free open source shopping cart as a stock photo website.  I've modified the heck out of it and so am encountering problems because the functions that were initally doing the jobs are no longer being called hence creating some minor bugs.  The main problem I'm having right now is because of smarty.  This was designed with the smarty template engine and I don't know nothing about it.  

when I display the categories in the amdinistrative section of my site, I also display the count for the products in each category.   The problem is that this count was being retrieved from a table that was being upldate every time a product or service was added.  Now, I don't want to use htis.   I prefer to just count the entries in the DB and return the count with mysql_num_rows.

I did this, and even figured out how to assigne the  variable to smarty.  this variable is being assigned in a "while" statement and should change with every category, but now, it displays the same number everywhere.  It's is the correct count of the selected category, but not for each category... don't know if I'm explaining this right here...  

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);
		//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;
		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);
			$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);
		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 *}
<td valign="top" bgcolor="#E2E2FF" width="25%">
	<table width="100%" border="0">
	 <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>
	 {section name=i loop=$categories}
	 <td>{section name=j loop=$categories[i][5] max=$categories[i][5]}&nbsp;&nbsp;&nbsp;&nbsp;{/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 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>
	<br><center>[ <a href="javascript:open_window('category.php?w=-1',400,400);">{$smarty.const.ADD_BUTTON}</a> ]</center><br>
any help is appreciated...
Avatar of John Account
John Account

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answers