Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
| Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2006, 05:02 AM
Registered User
 
Join Date: Jun 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stand alone categories tree for OScommerce

Hi,

I am trying to build a stand alone categories tree for osCommerce.

I am getting this error:


Code:
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:
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 ?


 
Old January 10th, 2006, 07:48 AM
Registered User
 
Join Date: Jun 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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/javascripts/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.categ ories_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!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Does the p stand for php or perl ciderpunx BOOK: Professional LAMP ISBN: 0-7645-9723-X 2 October 27th, 2011 02:06 PM
UPS shipping problem for Canada with osCommerce snowbydave1 PHP How-To 0 June 5th, 2008 05:14 AM
Running the examples on a stand alone computer MustfaZfar BOOK: ASP.NET AJAX Programmer's Reference : with ASP.NET 2.0 or ASP.NET 3.5 ISBN: 978-0-470-10998-4 0 December 13th, 2007 01:49 PM
Dowgraded to 4 from 5 for osCommerce crashcraddock Pro PHP 2 July 5th, 2006 08:41 AM
creating stand alone exe mr_bharathi General .NET 3 November 30th, 2004 08:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.