TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-19-2008, 10:06 AM   #1 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default My dynamic menu

Hi there!

I have written a dynamic menu. In one tabel I have the titles of the menu. Ex: Home & shop etc.

In another table I have the subtitles. Ex: When you click on shop, all the subtitles connected to shop should appear right underneath the title. Like this:

Home
Shop(active)
Good shop
Medium Shop
Bad shop
Contact

I think you understand. I connect those subtitles and titles with a id_parent, so all subtitles have the same id_parent as their respective title. But instead of the subtitles just appearing right under its title, it appears under every title in the menu. It extracts the right subtitles from the database, but print them under all titles. I think the problem lies in, how the udskriv_menu(); is chosen, but I do not know how to solve it...

Here is my title:

php Code:
$query=mysql_query("select * from a_spil order by titel asc");
while ($result=mysql_fetch_array($query)){



           echo '<div style="width:100%;height:19px;_height:24px;padding-top:5px;_padding-top:1px;">';
  echo '<div style="float:left;display:inline;" style="margin-top:4px;">';
   echo '<a href="index.php?mode='.$result[mode].'&mode2=spil&action=vis_spil&spil='.$result[id].'&overordnet='.$result[id_parent].'" title="Vuelta a Espaņa" style="margin:4px 0px 0px 17px;" class="menupunkt">';
    echo $result[titel];
   echo '</a>';
  echo '</div>';
  echo '<div style="float:right;margin:5px 0px 0px 0px;_margin:9px 0px 0px 0px;"><img src="grafik/menupunkt_pil.gif" style="margin-right:16px;"></div>';
 echo '</div>';
 echo '<div style="height:1px;width:100%;"><img src="grafik/menupunkt_skillelinie.gif" alt="" /></div>';
// If any title has been chosen, now the subtitles will appear in this form.
//overordnet is the id_parent of the title

if ($_REQUEST['overordnet']=="3333"){
 udskriv_menu();
// echo '<div style="height:1px;width:100%;"><img src="grafik/menupunkt_skillelinie.gif" alt="" /></div>';

 }
}
Here is my function:
php Code:
function udskriv_menu(){

 $aquery=mysql_query("select * from a_kategorier where id_parent='$_REQUEST[overordnet]' order by sortering asc");
 while($result=mysql_fetch_array($aquery)){
   $aquery2=mysql_query("select * from a_spil where id_parent='$id_parent'");
while ($result2=mysql_fetch_array($aquery2)){

  echo '<div style="width:100%;height:19px;_height:24px;padding-top:5px;_padding-top:1px;">';
   echo '<div style="float:left;display:inline;" style="margin-top:4px;">';
    echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php?mode='.$_REQUEST['mode'].'&mode2='.$result["struktur"].'&action=vis_'.$result["action2"].'&spil='.$result2["id"].'&id='.$result["id"].'" title="'.$result["titel"].'" style="margin:4px 0px 0px 17px;" class="menupunkt">';
     echo $result["titel"];
    echo '</a>';
   echo '</div>';
   echo '<div style="float:right;margin:5px 0px 0px 0px;_margin:9px 0px 0px 0px;"><img src="grafik/menupunkt_pil.gif" style="margin-right:16px;"></div>';
  echo '</div>';
  echo '<div style="height:1px;width:100%;"><img src="grafik/menupunkt_skillelinie.gif" alt="" /></div>';
  $nummer++;
  $antal_emner='0';
  udskriv_undermenu($result["id"],1);

}
}
}

Last edited by Wildhoney : 01-19-2008 at 01:00 PM. Reason: A little syntax highlighting
lesP is offline  
Reply With Quote
Old 01-19-2008, 10:09 AM   #2 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default

Oops. I didnt see this "post code" function. Should I post me code in such one?
lesP is offline  
Reply With Quote
Old 01-19-2008, 11:18 AM   #3 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

I can't see a reason why you couldn't.

Advice: In the future, try to separate the HTML from the PHP as much as possible. Don't embed large blocks of html into echo/print statements. It's hard to read/debug and especially hard to change the presentation if you needed to do so.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-19-2008, 11:28 AM   #4 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
I can't see a reason why you couldn't.
Couldn't what?

What happens is that when a title is "clicked", the menu is shown like this:

Home
Good shop
medium shop
bad shop
Shop
Good shop
medium shop
bad shop

And this should only be under shop.
lesP is offline  
Reply With Quote
Old 01-19-2008, 02:11 PM   #5 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

I meant shouldn't.

Now, for the problem. I don't really understand what you're trying to pull there, but here's an idea of what it should look like:

PHP Code:
// go through and display the categories
while( $category mysql_fetch... )
{
    echo 
$category['name'];

    
// if this category is selected, print its subs
    
if( isset( $_GET['category'] ) && $_GET['category'] == $category['id'] )
    {
        while( 
$subcategory mysql_fetch... )
        {
            echo 
$subcategory['name'];
        }
    }

__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-21-2008, 09:44 PM   #6 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default

Nice. Except it does not do the $subcategory
lesP is offline  
Reply With Quote
Old 01-21-2008, 09:53 PM   #7 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

woot?

Of course, if you needed limitless categories and subs, you would write a recursive function to do just that. Or use the MySQL way, as pointed out around here somewhere (nice approach, btw).
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-21-2008, 10:28 PM   #8 (permalink)
The Contributor
Newcomer 
 
Join Date: Jan 2008
Posts: 27
Thanks: 1
lesP is on a distinguished road
Default

Can you show with some code?
lesP is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:45 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design