cyberkid
Newbie
Posts: 1
Registered: 6/30/2005
Location: India
Member Is Offline
|
| posted on 6/30/2005 at 12:31 PM |
|
|
PHP , MySQL menu
Hi, how to load the mysql table values as a menu item using Tigra Tree Menu.
Thanx in advance
Cyberkid
|
|
|
mdsade
Junior Member
Posts: 4
Registered: 7/1/2005
Location: Las Vegas
Member Is Offline
|
| posted on 7/1/2005 at 08:33 PM |
|
|
PHP MySQL
I wrote this a long time ago for use. Its not the cleanest code but it should work. for version 2.0
Step 1: Create a file called menu_items.php where you have your other Tigra .js file and paste the below code. Change username, password and
database. Change script call in your page to point to menu_items.php insetead of .js.
| Code: |
<?
$link = mysql_connect('localhost', 'username', 'password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('database') or die('Could not select database');
$sql = "SELECT * FROM tigra_menu ORDER BY container,sub_container1,sub_container2";
$result = mysql_query($sql);
$prev_item= array('container'=>"", 'sub_container1'=>"", 'sub_container2'=>"");
$pri=0;$sec=0;
echo "var MENU_ITEMS = [\n";
while ($menu_item = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($menu_item['container'] != $prev_item['container']) {
if ($sec > 0){echo "],\n";$sec=0;}
if ($pri > 0){echo "],\n";$pri=0;}
echo "['".$menu_item['container']."','".$menu_item['link']."'";
$pri=0;
}else{
if($pri==0){echo ",null,\n";$pri++;}
if ($menu_item['sub_container1'] != $prev_item['sub_container1']) {
if($sec > 0){echo " ],\n";}
$sec=0;
echo " ['".$menu_item['sub_container1']."','".$menu_item['link']."'";
$sec++;
}else{
if($sec==1){echo ",null,\n";}
$sec++;
echo " ['".$menu_item['sub_container2']."','".$menu_item['link']."'],\n";
}
$pri++;
}
$prev_item = $menu_item;
}
if($sec > 0){echo " ],\n";}
if($pri > 0){echo "],\n";}
echo "];\n";
?>
|
Step 2: Create table called tigra_menu. Make 5 fields (primary_key,container,sub_container1,sub_container2,link).
sub_container1 & 2 must be allowed [NULL]
Step 3: Fill in the database similar to this. Container is your top element, sub_cont1 is 2nd, and sub_container2 is last. To get a child menu you
have to put the parents before it in the row.
| Code: |
+-------------+-----------+----------------+----------------+--------------------------------+
| primary_key | container | sub_container1 | sub_container2 | link |
+-------------+-----------+----------------+----------------+--------------------------------+
| 1 | Locations | [NULL] | [NULL] | locations/location_search.php |
| 2 | Locations | Manage | [NULL] | locations/location_manage.php |
| 3 | Locations | Manage | New | locations/location_new.php |
+-------------+-----------+----------------+----------------+--------------------------------+
|
Best of Luck
|
|
|
phishee
Junior Member
Posts: 2
Registered: 9/29/2005
Member Is Offline
|
| posted on 9/29/2005 at 11:45 PM |
|
|
Thanks for posting of your code. It has been quite helpful in familiarizing myself with the menu's structure.
One quick question: Is there a PHP interface or builder (that you or Tigra's developers have coded) which I could use to construct the menu and
store the parameters in MySQL as you have shown?
Thanks in advance,
phishee
|
|
|
mdsade
Junior Member
Posts: 4
Registered: 7/1/2005
Location: Las Vegas
Member Is Offline
|
| posted on 9/30/2005 at 05:50 PM |
|
|
To quickly answer your question, I have not built one.
If your talking about an interface for putting the menu entries(links) into the database. I normally just manually created or altered them during
the installation/upgrade of my php application. Also I had extra fields in the "tigra_menu" table for setting parameters such as privledges (wether
or not the link would display for the user). No need for an interface to make quick adjustments since adjustments were rarely done.
If your talking about an interface to change the layout of the menu such as fonts and sizes and such, I found the construction of the menu to be very
rigid and not easily adaptable for this type of design. As an example I changed the font on the menu. Since there was a size difference in the
display of the fonts it actually became larger than the cell in which it was typed and looked ugly so I had to adjust the size of the cell then adjust
the positioning of the submenu. It was a horrid undertaking. I would say design some style sheets with predefined characteristics and let the user
change between the templates if they want a different look/ feel. Even some of the seemingly smallest changes will quickly distort the display.
Maybe the newer versions are better adapted for this, but the version I used was not. As a person that uses stylesheet design I found this very
unforgiving in some areas.
|
|
|
phishee
Junior Member
Posts: 2
Registered: 9/29/2005
Member Is Offline
|
| posted on 9/30/2005 at 06:28 PM |
|
|
Thanks for taking the time to respond to my question. I am referring to the menu contents itself. I want our novice end-users to be able to build /
edit a menu at any time and not be overwhelmed with the task. Thus, a suitable interface would be perfect. I have not played with the menu's
styling but I am sure we'd disallow its tinkering from the user.
Thanks again for your help - It appears I may have to code the interface and see how it works out -
Phishee
|
|
|
uk6451
Newbie
Posts: 1
Registered: 12/9/2005
Member Is Offline
|
| posted on 12/9/2005 at 03:08 PM |
|
|
mdsade (or anyone else),
how i'm going to do exactly the same as u do (php,mysql) if i'm using the free version?
thank you.
|
|
|
mdsade
Junior Member
Posts: 4
Registered: 7/1/2005
Location: Las Vegas
Member Is Offline
|
| posted on 12/11/2005 at 09:52 AM |
|
|
I developed that for the free version. Give it a try. Unless the free version has changed in the last year or so it should work.
|
|
|
MaxxFusion
Junior Member
Posts: 2
Registered: 1/13/2006
Location: Cleveland, OH
Member Is Offline
|
| posted on 1/13/2006 at 07:03 PM |
|
|
Is anyone pulling info from an existing table? I want to be able to dynamically create the menu from my categories table. That way when I add a new
categorey to my store it gets added to the menu.
|
|
|