TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   PHP & MySQL Verticle Collapse menus (http://www.talkphp.com/advanced-php-programming/5028-php-mysql-verticle-collapse-menus.html)

mombunheng 10-15-2009 07:09 AM

PHP & MySQL Verticle Collapse menus
 
Hi everything,

I am trying to get the PHP & MySQL Verticle collapse menus work on my website with following concept:

- menu 1
- menu 2
- menu 3
- menu 3

If visitor click on menu 1 it will direct to that page of menu 1 and then list sub menus as the following concept:

- menu 1
. Testing Menus 1
. Testing Menus 2
. Testing Menus 3
. Testing Menus 4
- menu 2
- menu 3
- menu 3

Any body had experience with that please kindly let me know.

Regards,
Bunheng.

gamer13 10-15-2009 09:00 AM

At least I can give you the database table:

menu:
=====
id INT AUTO_INCREMENT PRIMARY KEY
name VARCHAR(255)
link VARCHAR(255)
parent_id INT DEFAULT '0'

And you fill it with:
1 | menu 1 | view.php?p=1 | 0
2 | menu 2 | view.php?p=2 | 0
3 | menu 3 | view.php?p=3 | 0
4 | menu 4 | view.php?p=4 | 0
5 | Testing menus 1 | view.php?p=1&action=1 | 1
6 | Testing menus 2 | view.php?p=1&action=2 | 1
7 | Testing menus 3 | view.php?p=1&action=3 | 1
8 | Testing menus 4 | view.php?p=1&action=4 | 1

You can also keep track of the 'order' in which every item has to be.

mombunheng 10-15-2009 02:04 PM

Any one can guide to how to select categories and its subcategories techniques.

fvisic 10-27-2009 04:12 PM

You can use this ....

TABLE (primary key "parent, child")
|parent | child | s_name | url
| ----- | 00001 | menu 1 | view.php?p=1
| ----- | 00002 | menu 2 | view.php?p=2
| ----- | 00003 | menu 3 | view.php?p=3
| ----- | 00004 | menu 4 | view.php?p=4
| 00001 | 00005 | Testing menus 1.1 | view.php?p=1&action=1
| 00001 | 00006 | Testing menus 1.2 | view.php?p=1&action=2
| 00001 | 00007 | Testing menus 1.3 | view.php?p=1&action=3
| 00001 | 00008 | Testing menus 1.4 | view.php?p=1&action=4
| 00002 | 00009 | Testing menus 2.1 | view.php?p=2&action=1
| 00002 | 00010 | Testing menus 2.2 | view.php?p=2&action=2
| 00002 | 00011 | Testing menus 2.3 | view.php?p=2&action=3
| 00002 | 00012 | Testing menus 2.4 | view.php?p=2&action=4
| 00012 | 00013 | Testing menus 2.4.1 | view.php?p=2&action=4&subacction=1
...
etc.

You must use recursion for every child
First level
SELECT * FROM table WHERE parent='-----'
second level
SELECT * FROM table WHERE parent='00001'

.....................
SELECT * FROM table WHERE parent='00002'

................
SELECT * FROM table WHERE parent='00012'

mombunheng 10-30-2009 08:34 AM

thanks for your participation for the menus design, I am currently using the following code let me know if you have any idea better than this.

CODE:
----------------------------------------------
<ul>
<li class="maintitle"><a href="/wcscambodia/section.php?sectid=<?php echo $sectid;?>"><?php echo $sect_name;?></a></li>
<?php
$currentcat = (int)($_GET['catid']);
$listid = '';
$sql = "SELECT cat_label, cat_id FROM tblcategories WHERE parent_sect = $sectid";
$result = dbQuery($sql);
while ($row = dbFetchAssoc($result)) {
?>

<li<?php if ($row['cat_id'] == $currentcat){$listid = ' id="current"'; echo $listid; }?>>
<a href="subsection.php?catid=<?php echo $row['cat_id'];?>"><?php echo $row['cat_label'];?></a>
</li>
<?php
if ($row['cat_id'] == $currentcat){
echo '<ul class="subul">';
$sqlm = "SELECT * FROM tblarticle WHERE article_cat = $currentcat";
$mresult = dbQuery($sqlm);
while ($rowm = dbFetchAssoc($mresult)){
?>
<li class="article"><a href="article.php?catid=<?php echo $currentcat;?>&page=<?php echo $rowm['article_id'];?>"><?php echo $rowm['article_title']?></a></li>
<?php
}
echo '</ul>';
}
?>
<?php }?>
</ul>

rguy84 11-06-2009 04:15 AM

I have made menus like this using straight php, not a database. how are the pages saved in the database?

mombunheng 02-19-2010 08:33 AM

Hi, originally the each menus have destination link or page ID, it looks like joomla framework, I am currently use on some project, I am looking for shorter way and fast performance.

rguy84 02-19-2010 05:17 PM

Are you legitimately still working on this? I only ask since it took over 3 months to get a reply. I haven't used Joomla much, so I don't know what you mean by it looks like joomla. Remember all a framework is is a pre-defined set of classes and/or functions, basically making your life/work easier.


All times are GMT. The time now is 07:13 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0