...

View Full Version : Menu from MySQL



johnmayer
03-23-2004, 09:26 AM
I am trying to automate menu creation, I'm still somewhat new at this, I managed to get a navigation system to work, (index.php?sectionid=xx&pageid=xx). I'm pretty sure I have no idea here and am completely off but here goes...


<?php
$G1 = mysql_query('SELECT * FROM section WHERE category = 1');
$G2 = mysql_query('SELECT * FROM section WHERE category = 2');
$GRAB = mysql_query('SELECT * FROM nav WHERE sectionid = "'. $sectid. '"');
?>

<div id="leftnav">
<?php

while($nav = mysql_fetch_array($G1)) {
$sectid = $nav['sectionid'];
$titlea = $nav['title'];
echo '<div class="box"><div class="boxtitle">'. $titlea .'</div><ul>';
while($nava = mysql_fetch_array($GRAB)) {
echo '<li><a href="#">'. $nava['name'] .'</a></li>';
}
echo '</ul></div>';
}


?>
</div>

<div id="rightnav">
<?php

while($nav = mysql_fetch_array($G2)) {
$sectid=$nav['sectionid'];
$titlea = $nav['title'];
echo '<div class="box"><div class="boxtitle">'. $titlea .'</div><ul>';
while($nava = mysql_fetch_array($GRAB)) {
echo '<li><a href="#">'. $nava['name'] .'</a></li>';
}
echo '</ul></div>';
}


?>
</div>


I got all the boxtitles and boxes to show up, but the list items do not :| Database is simple now, until I get it to work...
table 'section' has 3 columns: "category", "sectionid", "title"
table 'nav' has 2 columns: "sectionid" & "name"

I am trying to implement this completely wrong?

sidney
03-23-2004, 02:12 PM
$GRAB = mysql_query('SELECT * FROM nav WHERE sectionid = "'. $sectid. '"');

this line at top sectid is not set till futher down really needs to be

in while loop which starts around line 28


while($nav = mysql_fetch_array($G2)) {
$sectid=$nav['id'];
$GRAB = mysql_query('SELECT * FROM test WHERE id = "'. $sectid. '"');

Hawkmoon
04-01-2004, 04:23 AM
Dynamic Menus are the way to go! Here's a Menu Class I put together and have been using for a long time. Hope someone finds it useful.

-Hawkmoon



<?
/*
//############################## NOTES ###############################################
Works from MENU table which is
MENUID int(11) NOT NULL AUTO_INCREMENT PRI, //Unique ID
MENUITEM varchar(100) NOT NULL, //Display Name for menu item
MENUFILE varchar(100) NOT NULL, //File for href
GID int(11) //1-admin 2-superuser 3-client
ORDERID int(11) //Order for menu items
ICON varchar(100) NOT NULL, //File for icon
*/

//############################## objMenu Class ######################################
class objMenu {
var $database;
var $gid;
var $arrMenu = array();

function objMenu($database,$gid) {
$this->database = $database;
$this->gid = $gid;
$this->setMenu();
}

function getMenu($menuType) {
$str = "";
$str .= "<table border=0 cellpadding=0 cellspacing=0>";
foreach($this->arrMenu as $row) {
list($menuid,$menuitem,$menufile,$orderid,$icon) = $row;
//Currently items with an $orderid over 100 create a different menu
//To alter the menu length change the numbers below.
if($menuType=="right") {
$tempHigh = "200";
$tempLow = "100";
} else {
$tempHigh = "100";
$tempLow = "0";
}
if($orderid>$tempLow && $orderid<$tempHigh) {
$str .= "<tr><td>";
if($icon!="") {
$str .= "<a href='$menufile'><img src='$icon' border=0></a>";
} else {
$str .= "<a href='$menufile' class='menu' border=0>$menuitem</a>";
}
$str .= "</td></tr>";
}
}
$str .= "</table>";
return $str;
}

function setMenu() {
$sql = "SELECT MENUID, MENUITEM, MENUFILE, ORDERID, ICON";
$sql .= " FROM $this->database";
$sql .= " WHERE GID='$this->gid'";
$sql .= " ORDER BY ORDERID ASC";

$result = mysql_query($sql) or DIE("ERROR:" . mysql_error());
while($row = mysql_fetch_row($result)) {
$this->arrMenu[] = $row;
}
}

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum