Current location: Hot Scripts Forums » Programming Languages » PHP » Drop Down Menu populated by Database


Drop Down Menu populated by Database

Reply
  #1 (permalink)  
Old 08-19-04, 03:46 PM
maweber98 maweber98 is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Drop Down Menu populated by Database

I'm trying to create a drop down menu that is populated by a mySQL table. The table is three columns: ID, Breeds, Sizes. I want the drop down menu to be populated by the Breeds table. One the user selects a Breed from the list I want the appropriate "Size" to be displayed. So far I have been able to populate the menu with the Breeds, but I haven't figured out how to display the results of the selection. Here is what I have so far:

<script language="JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>

<form name = "form" action = "haltiresults2.php" Method = "POST">
<select name="selObj" onChange="MM_jumpMenu('parent',selObj,0)">
<option selected>Select Breed</option>

<?
$username = "username"; // The username you created for this database.
$password = "password"; // The password you created for the username.
$usertable = "Halti_Sizes"; // The name of the table you made.
$dbName = "DatabaseName"; // This is the name of the database you made.

MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");

$query = mysql_query("SELECT * FROM Halti_Sizes ORDER BY 'Breeds' ASC");
while($row = mysql_fetch_array($query)) {

print '<option value="haltiresults2.php?ID='.$row["ID"].'">'.$row["Breeds"];
}
?>
</select></form>


I'm not sure what I'm doing wrong. The "ID" shows up in the URL of the second page "haltiresults2.php" , but I can't figure out how to get it to display any of the information that corresponds to that ID.

Does anyone have any suggestions. Any help would be greatly appreciated!!! Thank you so much!
Reply With Quote
  #2 (permalink)  
Old 08-19-04, 03:55 PM
lool49 lool49 is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
not sure what you want to do? is it on the haltresults2.php page you are trying to show the results? If so you need to have a new sql query to fech that info
"select * from Halti_Sizes where id=('$id')"
Reply With Quote
  #3 (permalink)  
Old 08-20-04, 08:24 AM
maweber98 maweber98 is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Drop down menu

Yes, I'm trying to show the results on haltiresults2.php page. What kind of query would I need to use to fetch that information?
Reply With Quote
  #4 (permalink)  
Old 08-20-04, 09:21 AM
Andy1984's Avatar
Andy1984 Andy1984 is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

<script language="JavaScript"> 

<!-- 
function MM_jumpMenu(targ,selObj,restore){ //v3.0 
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 
if (restore) selObj.selectedIndex=0; 

//--> 
</script>

<form name = "form" action = "haltiresults2.php" Method = "POST">
<select name="selObj" onChange="MM_jumpMenu('parent',selObj,0)"> 
<option selected>Select Breed</option>

<? 
$username 
"username"// The username you created for this database. 
$password "password"// The password you created for the username. 
$usertable "Halti_Sizes"// The name of the table you made. 
$dbName "DatabaseName"// This is the name of the database you made. 

MYSQL_CONNECT($hostname$username$password) OR DIE("DB connection unavailable");
@
mysql_select_db"$dbName") or die( "Unable to select database"); 

$query mysql_query("SELECT * FROM Halti_Sizes ORDER BY 'Breeds' ASC"); 
while(
$row mysql_fetch_array($query)) { 
//notice the change in the url bellow
print '<option value="haltiresults2.php?action=breeds&id='.$row["ID"].'">'.$row["Breeds"];

?>
</select></form>
contents of haltiresults2.php:
PHP Code:

<?PHP 


function Getdata($id){ 
//add an sqlquery here to grab the data from breeds id
//and have it displaye as you wish
echo "$id"


switch(
$_GET['action']) { 
    case 
'breeds'
        
Getdata($_GET['id']); 
        break; 

?>
Reply With Quote
  #5 (permalink)  
Old 08-20-04, 10:36 AM
maweber98 maweber98 is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thank You - Drop Down Menu Works

Thank you so much Andy1984! The drop down menu works perfectly! I can't thank you and the others enough. Your the best!!
Reply With Quote
  #6 (permalink)  
Old 08-20-04, 10:43 AM
Andy1984's Avatar
Andy1984 Andy1984 is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
glad it works for you
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
drop down menu with mysql stealth04 PHP 3 06-21-04 11:29 AM
Need help with populating drop down menu... NCC1701 PHP 0 04-28-04 07:10 AM
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 04:22 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.