Current location: Hot Scripts Forums » Programming Languages » PHP » putting content in a drop down menu


putting content in a drop down menu

Reply
  #1 (permalink)  
Old 06-22-03, 08:00 AM
tom tom is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Question putting content in a drop down menu

hey guys! i have a very small CMS right now on my site.
it is working great, but i want to change the way the menu is displayed. right now it shows just text links, but i want to replace the text links with a dropdown menu.

this is the code i use at the moment to show the menu.
PHP Code:

<?php

 $result 
mysql_query("SELECT * FROM menu ORDER BY 'sort' ASC");
 while(
$row mysql_fetch_array($result)){


/* display menu items  */
echo "<a href=\"index.php?m=$row[mid]&s=0\">$row[menu]</a><br>";
?>
this generates something like:
Home
Downloads
Info

but now i want it to show these things in the dropdown menu.

how do i edit the php code i pasted here, to show my items in a dropdown menu?

thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 06-22-03, 08:46 AM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Greetingz...

To get the drop down to display:

PHP Code:

<SELECT>

<?php
  $result 
mysql_query("SELECT * FROM menu ORDER BY 'sort' ASC");

  while(
$row mysql_fetch_array($result))
  {
    
/* display menu items  */
    
echo '<OPTION VALUE="' $row[mid] . '">' $row[menu] . "</OPTION>";
  }
?>
</SELECT>
To make the menu jump you'll need to add some JavaScript:
PHP Code:

<SCRIPT LANGUAGE="JavaScript">

  function 
jumptourl()
  {
    
window.location 'index.php?m=' frmMenu.MenuItem '&s=0';
  }
</SCRIPT>
<FORM NAME="frmMenu" OnSubmit="jumptourl()">
  <SELECT NAME="MenuItem" OnChange="frmMenu.submit()">
  ...
  </SELECT>
</FORM> 
Basically that'll work...
Hope it helps...
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Reply With Quote
  #3 (permalink)  
Old 06-22-03, 03:42 PM
tom tom is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
worked like a charm, although for it to work i had to modify that menu jump code a bit. changed it to this:

PHP Code:

<SCRIPT LANGUAGE="JavaScript">

  function 
jumptourl()
  {
    
window.location '?m=' frmMenu.m.Value;
  }
</SCRIPT> 
anyhow, its sorted. thanks!
Reply With Quote
  #4 (permalink)  
Old 06-22-03, 04:18 PM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
of cource...
.value

Well... glad it works...
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Reply With Quote
  #5 (permalink)  
Old 06-22-03, 04:19 PM
tom tom is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
me too ;D
Reply With Quote
  #6 (permalink)  
Old 07-03-03, 05:21 AM
tom tom is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
sorry to bring this thread back up, but i seem to be having a problem

the first item in the generated list doesn't seem to work.
it creates the link correctly, and entering the link in manually in the URL window works fine ofcourse, but when people click it, nothing happens. what's up with this?
the code works fine for all the other options in the select form.. just not the first one.
Reply With Quote
  #7 (permalink)  
Old 07-03-03, 05:29 AM
tom tom is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
just thought i should add some code for the sake of clarity

here is the javascript that handles the menu jumper:
PHP Code:

<SCRIPT LANGUAGE="JavaScript">

  function 
navigate()
  {
    
window.location.href 'index.php?m=' frmMenu.m.Value;
  }
</SCRIPT> 
and this is dropdown itself:
PHP Code:

<FORM NAME="frmMenu" OnSubmit="navigate()">

<
SELECT NAME="m" OnChange="frmMenu.submit()">
            <
OPTION VALUE="1">home</OPTION>
            <
OPTION VALUE="2">option two</OPTION>
            <
OPTION VALUE="3">option 3</OPTION>
            <
OPTION VALUE="4">updates</OPTION>
</
SELECT>
</
FORM
if anybody could help that'd be real cool..
Reply With Quote
  #8 (permalink)  
Old 07-04-03, 02:25 PM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
The reason it doesn't is that javascript doesn't fire the OnChange event for the currebtly selected item...

I normally use something like this...
PHP Code:

<?php

  
function drawOption($sDesc$sValue$sCurrent);
  {
    
$Option '<OPTION VALUE=' $sValue;

    if (
$sValue == $sCurrent)
    {
      
$Option .= ' SELECTED';
    }

    
$Option .= '>' $sDesc '</OPTION>';

    echo 
$Option;
  }

  if (ISSet(
$_REQUEST["m"]))
  {
    
$m $_REQUEST["m"];
  }
  else
  {
    
$m '';
  }

?>
<FORM NAME="frmMenu" OnSubmit="navigate()">
<SELECT NAME="m" OnChange="frmMenu.submit()">
<?php
  
if (empty($m))
  {
    
drawLink('Links...'''$m);
  }

  
drawLink('Home',       '1'$m);
  
drawLink('Option two''2'$m);
  
drawLink('Option 3',   '3'$m);
  
drawLink('Updates',    '4'$m);
?>
</SELECT>
</FORM>
of cause you could leave out the (Links...) if your first page is $m=1...

Hope it helps and makes sense...
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
drop down with link perleo PHP 0 09-06-03 04:35 PM
drop the lowest number TheLaughingBandit ASP 2 08-30-03 01:57 PM
Looking for free poll script with drop-down menu! filson PHP 5 07-30-03 10:21 AM
menu?? superman PHP 3 07-14-03 01:59 AM
xhtml + css rockerBOO CSS 6 06-20-03 02:47 PM


All times are GMT -5. The time now is 07:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.