Jump to content

Category Integration


googlit

Recommended Posts

Hi all,

 

Im hoping to get a little help or to be pointed in the right direction,

 

what im trying to do is make a DB led category system that will pull data from a table and publish. hopefully looking something like this:

 

-category1

-subcat1

-subcat2

-catrgory2

-subcat1

-subcat2

-category3

-category4

 

 

etc etc etc...

 

my table is set up as so:

 

Column Type NULL Default Comments

id int(11) No auto Increment - Primary Key

catName Varchar(255) No category Title

parentCat int(11) No 0 Parent category ID for Sub Categories

catDescrip varchar(255) YES NULL Text description of category

catOrder varchar(255) YES NULL List Order of Categories

isActive int(11) NO 1 Is Active = 1 Innactive = 0

 

 

my current page design for the category menu is this:

 

<div style="float: left" id="my_menu" class="sdmenu">
<div>
<span>Category 1</span>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
</div>
<div>
<span>Category 2</span>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
</div>
<div class="collapsed">
<span>Category 3</span>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
</div>
<div>
<span>Category 4</span>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
<a href="link1.php">link1</a>
</div>
</div>

 

any help would be appreciated as i am unsure on how to begin with this.

Link to comment
Share on other sites

ok, so after a lot of reasearch i have found and compiled a script that does that i want, the problem now exists that i have no idea how to impliment it with my current javascript... the two files are below.........

 

 

The Function:

 

<?php
function hasChild($parent_id)
{
$sql = "SELECT COUNT(*) as count FROM categories WHERE parent_id = '" . $parent_id . "'";
$qry = mysql_query($sql);
$rs = mysql_fetch_array($qry);
return $rs['count'];
}

function CategoryTree($list,$parent,$append)
{
$list = '<li>'.$parent['name'].'</li>';

if (hasChild($parent['id'])) // check if the id has a child
{
 $append++;
 $list .= "<ul class='child child".$append."'>";
 $sql = "SELECT * FROM categories WHERE parent_id = '" . $parent['id'] . "'";
 $qry = mysql_query($sql);
 $child = mysql_fetch_array($qry);
 do{
 $list .= CategoryTree($list,$child,$append);
 }while($child = mysql_fetch_array($qry));
 $list .= "</ul>";
}
return $list;
}
function CategoryList()
{
$list = "";

$sql = "SELECT * FROM categories WHERE (parent_id = 0 OR parent_id IS NULL)";
$qry = mysql_query($sql);
$parent = mysql_fetch_array($qry);
$mainlist = "<ul class='parent'>";
do{
 $mainlist .= CategoryTree($list,$parent,$append = 0);
}while($parent = mysql_fetch_array($qry));
$list .= "</ul>";
return $mainlist;
}
?>

 

and the page code (styles etc)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="sdmenu/sdmenu.css" />
   <script type="text/javascript" src="sdmenu/sdmenu.js">

   </script>
   <script type="text/javascript">
   // <![CDATA[
   var myMenu;
   window.onload = function() {
       myMenu = new SDMenu("my_menu");
       myMenu.init();
   };
   // ]]>
   </script>
</head>

<body>
<!--Navbar test--------------------->


<div style="float: left" id="my_menu" class="sdmenu">
  <div>
    <span>one
       </span>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
  </div>
  <div>


    <span>two</span>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
  </div>
  <div class="collapsed">


    <span>three</span>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
  </div>
  <div>


    <span>four</span>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
    <a href="link1.php">link1</a>
  </div>
   </div>


</body>
</html>

 

Can anyone shed some light on this, i have always had issues with merging the two together and escaping etc....

Edited by googlit
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.