Current location: Hot Scripts Forums » Programming Languages » PHP » Drop down menu trouble


Drop down menu trouble

Reply
  #1 (permalink)  
Old 04-16-04, 08:31 AM
NCC1701's Avatar
NCC1701 NCC1701 is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Drop down menu trouble

Having trouble creating functions to display a list of values in a drop down menu, all i want to display is the menu option, this will evetually be coded so that when the user selects the menu name, the menu is displyed in a text box and will be able to edit it.

PHP Code:

<?php 
function get_menus()
{
  
//query database
  
$conn db_connect();
  
$query "select menu_name
     from menu
   where menu_id = 
$menu_id";
  
$result = @mysql_query($query);
  if (!
$result)
   return 
false;
  
$num_menus = @mysql_num_rows($result);
  if (
$num_menus == 0)
    return 
false;
  
$result mysql_result($result0'menu_name');
  return 
$result;
}

 

function 
display_menu_form()
{
?>
  <form method="post" action="">
  <table align="center" border="0">
  <tr>
    <td><select name="menu_name">
 <?php 
   
//selects menu list from menu database
   
$menu_array=get_menus();
   foreach (
$menu_array as $menu)
   {
     echo 
'<option value="';
  echo 
$menu['menu_name'];
  echo 
'"';
   }  
 
?>
 </select></td>
  </tr>
  </table>
  </form>
<?php 
}
?>
Reply With Quote
  #2 (permalink)  
Old 04-16-04, 09:37 AM
NCC1701's Avatar
NCC1701 NCC1701 is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
i think its to complecated above, can anyone provide a very simple script to list database items in a drop down menu?
Reply With Quote
  #3 (permalink)  
Old 04-16-04, 11:45 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
it depends on what does the function get_menus() !
but generaly this is how you do drop downs from mysql:
PHP Code:

$fetch mysql_query("SELECT value, item FROM table_1")or

die(
mysql_error());

echo 
'<form method="POST" action="'.$_SERVER['PHP_SELF'].'">
<select name="menu_name">'
;

while(
$info mysql_fetch_assoc($fetch)) {
  echo 
'<option value="'.$info['value'].'">'.$info['item'].'</option>';
}
echo
'</select>
</form>'

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #4 (permalink)  
Old 04-16-04, 11:51 AM
NCC1701's Avatar
NCC1701 NCC1701 is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
thats really usefull thanks mate.

all i need to know now is when you select a option from the menu can you get it to display the corressponding data to do with the menu name?
Reply With Quote
  #5 (permalink)  
Old 04-16-04, 11:55 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
altho I am not very sure about what you mean, but I think you will need to use OnChange so when you select an item it submits to the corressponding data ..
here, JavaScript is involved ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #6 (permalink)  
Old 04-16-04, 12:00 PM
NCC1701's Avatar
NCC1701 NCC1701 is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
what i mean is, say in my database i have two fields, menu_name and menu_text.


menu_name would be something such as Lunch, Starters, Mains etc

the menu_text would be the text in the database with all the menu items on.

what i want to be able to do is, when you click a menu option the menu text is displayed in a textarea below.

am i making sense?
Reply With Quote
  #7 (permalink)  
Old 04-16-04, 12:07 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
oh, this also needs JavaScript with OnChange as I said

but I am not sure how it can be done since I am not expert in JavaScript..
but search the web for onchange uses and I am usre you will find good answers !
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #8 (permalink)  
Old 04-16-04, 12:28 PM
NCC1701's Avatar
NCC1701 NCC1701 is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
are you sure there is no way of doing without javascript, like a master detail form? if there isnt ill have a bash at the javascript
Reply With Quote
  #9 (permalink)  
Old 04-17-04, 05:42 AM
NCC1701's Avatar
NCC1701 NCC1701 is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
bump for replys
Reply With Quote
  #10 (permalink)  
Old 04-17-04, 05:54 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

I would definitely use onChange event to refresh the page with the first combobox's selection as a GET var (and retrieve the corresponding data from the database with PHP upon refreshing the page).

With PHP, there is no way to listen to events once the page (i.e. HTML contents) is loaded. You have to use client-side scripting such JavaScript to handle these. I've heard ASP.NET is event-based and can do such, but I am not 100% sure how it does it.
__________________
Blavv =|
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
Creating a drop down menu ? ? ? Spreegem PHP 4 03-09-05 09:34 AM
Creating a drop down menu? Spreegem HTML/XHTML/XML 8 08-30-04 11:40 PM
Replacing drop down form menu with fixed value NCC1701 PHP 1 04-05-04 02:47 PM
drop down menu problem !!! nurqeen PHP 1 02-08-04 08:07 PM
putting content in a drop down menu tom PHP 7 07-04-03 02:25 PM


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