All pastes #110951 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-08-02 01:26 UTC
rendered paste body
La idea es la siguiente: 

El menu iria repartido en dos tablas: 

Tabla No 1: 

categories: que contendría un id, el id de la categoria padre 

y otra tabla así: 

categories_description: id (del menu) y el nombre. 

El script que hice yo es el siguiente: 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
	<title>Folder tree with Drag and Drop capabilities</title>
	<script type="text/javascript" src="js/ajax.js"></script>
	<script type="text/javascript" src="js/drag-drop-folder-tree.js">
	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, July 2006
	
	Update log:
	
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact.
	
	For more detailed license information, see http://www.dhtmlgoodies.com/index.html?page=termsOfUse 
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	
	</script>
	<link rel="stylesheet" href="css/drag-drop-folder-tree.css" type="text/css"></link>
	
</head>
<body>
<ul id="dhtmlgoodies_tree2" class="dhtmlgoodies_tree">
  <li id="node10000" noDrag="true" noSiblings="true"><a href="#">Mi catálogo</a>
<?php


/**
 * Función que construye el browser de categorias
 * Con ayuda de OSCommerce
 *
 */

function tep_get_category_tree($parent_id = '0', $spacing = '', $exclude = '', $category_tree_array = '', $include_itself = false)
{
  $conexion=mysql_connect("localhost","root","");
  $db=mysql_select_db("tienda",$conexion);

  $languages_id = '3';
  if (!is_array($category_tree_array)) $category_tree_array = array();
  if ((sizeof($category_tree_array) < 1) && ($exclude != '0') ) $category_tree_array[] = array('id' => '0', 'text' => "Catalogo");
  
  $categories_query = "select c.categories_id, cd.categories_name, c.parent_id from categories  c, categories_description cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = '" . (int)$parent_id . "' order by c.sort_order, cd.categories_name";
  $resultado=mysql_query($categories_query);
  $numero=mysql_num_rows($resultado);
  if($numero == 0) {
    echo "</li>";
  }
  else {
    echo "\t<ul>\n";
    while ($categories = mysql_fetch_array($resultado)) {
      //if ($exclude != $categories['categories_id']){ 
      $category_tree_array[] = array('id' => $categories['categories_id'], 'text' => $categories['categories_name']);
      echo "\t\t<li id=\"node".$categories['categories_id']."\"><a href=\"#\">".$categories['categories_name']."</a>\n";
    tep_get_category_tree($categories['categories_id'], '&nbsp;&nbsp;&nbsp;', $exclude, $category_tree_array); 
    }
    echo "</ul>";
  }
}

$arbol=tep_get_category_tree();
?>
 </li>
</ul>
	<script type="text/javascript">	
	treeObj = new JSDragDropTree();
	treeObj.setTreeId('dhtmlgoodies_tree2');
	treeObj.setMaximumDepth(7);
	treeObj.setMessageMaximumDepthReached('Maximum depth reached'); // If you want to show a message when maximum depth is reached, i.e. on drop.
	treeObj.initTree();
	</script>
</body>
</html>