|
Subject:
|
Stand alone categories tree for OScommerce
|
|
Posted By:
|
superdos
|
Post Date:
|
1/10/2006 4:02:32 AM
|
Hi,
I am trying to build a stand alone categories tree for osCommerce.
I am getting this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/insitevi/public_html/crg-shop/mirror/category_tree.php on line 50
Here is the entire code:
$dbh=mysql_connect ("***", "***", "***") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("***");
mysql_query("SET NAMES 'hebrew'");
class osC_CategoryTree {
var $root_category_id = 0,
$max_level = 0,
$data = array(),
$root_start_string = '',
$root_end_string = '',
$parent_start_string = '',
$parent_end_string = '',
$parent_group_start_string = '<ul class="sitemap">',
$parent_group_end_string = '</ul>',
$child_start_string = '<li>',
$child_end_string = '</li>',
$spacer_string = '',
$spacer_multiplier = 1;
function osC_CategoryTree ($load_from_database = true) {
$categories_query = mysql_query("SELECT * FROM categories,categories_description WHERE categories.categories_id = categories_description.categories_id ORDER by categories.parent_id, categories.sort_order,categories_description.categories_name");
$this->data = array();
while ($categories = mysql_fetch_array($categories_query)) {
$this->data[$categories['parent_id']][$categories['categories_id']] = array('name' => $categories['categories_name'], 'count' => 0);
}
}
function buildBranch($parent_id, $level = 0) {
$result = $this->parent_group_start_string;
if (isset($this->data[$parent_id])) {
foreach ($this->data[$parent_id] as $category_id => $category) {
$category_link = $category_id;
$result .= $this->child_start_string;
if (isset($this->data[$category_id])) {
$result .= $this->parent_start_string;
}
if ($level == 0) {
$result .= $this->root_start_string;
}
$result .= str_repeat($this->spacer_string, $this->spacer_multiplier * $level) . '<a title="'. $category['name'] . '" href="mirror.php?".$category_link.">';
$result .= $category['name'];
$result .= '</a>';
if ($level == 0) {
$result .= $this->root_end_string;
}
if (isset($this->data[$category_id])) {
$result .= $this->parent_end_string;
}
$result .= $this->child_end_string;
if (isset($this->data[$category_id]) && (($this->max_level == '0') || ($this->max_level > $level+1))) {
$result .= $this->buildBranch($category_id, $level+1);
}
}
}
$result .= $this->parent_group_end_string;
return $result;
}
function buildTree() {
return $this->buildBranch($this->root_category_id);
}
}
mysql_close($dbh);
$osC_CategoryTree = new osC_CategoryTree; echo $osC_CategoryTree->buildTree();
Can anyone help me with my problem ?
|
|
Reply By:
|
superdos
|
Reply Date:
|
1/10/2006 6:48:12 AM
|
Thank to all of you that wanted to help - I solved it! The tree categories is using a javascript class call dtree yuo can find it here: http://www.destroydrop.com/ s/tree/ and this is the place to give credit to the developer: Geir Landrö.
The code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head> <title>Category tree</title>
<link rel="StyleSheet" href="dtree.css" type="text/css" /> <script type="text/javascript" src="dtree.js"></script>
</head>
<body> <script type="text/javascript"> <!--
d = new dTree('d'); d.config.folderLinks=false; d.add(0,-1,'Head title');
<? $dbh=mysql_connect ("***", "***", "***") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("***");
$categories_query = mysql_query("SELECT * FROM categories,categories_description WHERE categories.categories_id = categories_description.categories_id ORDER by categories.parent_id, categories.sort_order,categories_description.categories_name"); while ($categories = mysql_fetch_array($categories_query)) { extract ($categories);
echo("
d.add($categories_id,$parent_id,'$categories_name','mirror.php?cat=$categories_id');
"); }
mysql_close($dbh);
?> document.write(d); </script>
I have tried it, and its working perfect!
|
|