MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 3rd, 2004, 09:27 PM
Mr_Bonds Mr_Bonds is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 Mr_Bonds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Double drop down in page php using data from mysql (recall)

Hi,
I have just posted my question about create drop down button using data with mysql code. May be the questions are not very clear, so I think that I repost this item one more time. I have two questions.

1- I need to create two drop down in page.php, one for category and the other for article. The data of category and article will be retrieved from mysql. The drop down for article depends on the value selected on category drop down.
Actually, the results of my code is only the creation of one drop down category but I cannot retrieve article from data base to create the other drop down for article which is depended to the value selected of the category.
How I could change value with php to create article drop down. I tried onChange but it didn't work.

<?php
include "inc/common_db.inc";

$categorie=$_POST['categorie'];
$article=$_POST['description'];
$no_article=$_POST['no_article'];
$no_categorie=$_POST['no_categorie'];

$action=$_POST['action'];

// Connection to BD
$id_lien = db_connect("novo163_bdevengarsal");
if(!$id_lien) die(sql_error());

//Request categories into BD
$categorie = "SELECT no_categorie, categorie FROM categorie_t";
$resultat_cat = mysql_query($categorie);
if(!$resultat_cat) error_message(sql_error());



$options_cat="";

//make category drop down
while ($row_cat=mysql_fetch_array($resultat_cat)) {

$no_categorie=$row_cat["no_categorie"];
$categorie=$row_cat["categorie"];
$options_cat.="<OPTION VALUE=\"$no_categorie\">".$categorie;

}


?>

//code in html
<tr>
<td align="left" valign="top">
<select name="categorie">
<Option value=0>Categories
<?=$options_cat?>
</select>
</td>

<td align="left" valign="top">
<select name="articles">
<option value=0>Articles
</select>
</td>

2- I have to add and remove the article of drop down in another area text and otherwise (by add and remove button) to make a list of products, so I liked to know if I have to make an array to keep all items? How I could do that?

I am very appreciated about your help.
Mr_Bonds

Reply With Quote
  #2  
Old August 5th, 2004, 09:35 AM
dejbjerg dejbjerg is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 1 dejbjerg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
//Perhaps something along these lines:

//The database fields and some variable names are in danish, but you should be able to figure it out anyway :)
//quick translation:
//grupper = groups
//varer = products
//navn = name

<html>
<body>
<?php

$server = "localhost";
$brugernavn = "******";
$password = "******";

mysql_connect($server, $brugernavn, $password)
or die( "Unable to connect\n". mysql_error() );

mysql_select_db("test")
or die("Unable to select db ".mysql_error()."\n");

$id = $_GET['id'];

echo'<form name="testform">';
$q = mysql_query("SELECT * FROM grupper");
echo"<select name=\"gruppe\" onChange=\"Load_id()\">";
while($row = mysql_fetch_array($q)) {
$selected = ($row["gruppe_id"] == $id)? "SELECTED":"";
echo"<option value=\"".$row['gruppe_id']."\"". $selected." >".$row['gruppe_navn']."</option>";
}
echo"</select>";


$q2 = mysql_query("SELECT * FROM varer WHERE vare_gruppe_id = $id");
echo"<select name=\"vare\">";
while($row = mysql_fetch_array($q2)) {
echo"<option value=\"".$row['vare_id']."\">".$row['vare_navn']."</option>";
}
echo"</select></form>";
?>

<script type="text/javascript">
function Load_id()
{
var id = document.testform.gruppe.options[document.testform.gruppe.selectedIndex].value
var id_txt = "?id="
location = id_txt + id
}
</script>
</BODY>
</HTML>

//DB_DUMPS////////////////////////////

CREATE TABLE `grupper` (
`gruppe_id` int(11) NOT NULL auto_increment,
`gruppe_navn` varchar(60) NOT NULL default '',
PRIMARY KEY (`gruppe_id`)
) TYPE=MyISAM AUTO_INCREMENT=3 ;

INSERT INTO `grupper` VALUES (1, 'testgruppe1');
INSERT INTO `grupper` VALUES (2, 'testgruppe2');


CREATE TABLE `varer` (
`vare_id` int(11) NOT NULL auto_increment,
`vare_gruppe_id` int(11) NOT NULL default '0',
`vare_navn` varchar(60) NOT NULL default '',
PRIMARY KEY (`vare_id`)
) TYPE=MyISAM AUTO_INCREMENT=5 ;

INSERT INTO `varer` VALUES (1, 1, 'testvare1');
INSERT INTO `varer` VALUES (2, 1, 'testvare2');
INSERT INTO `varer` VALUES (3, 2, 'testvare3');
INSERT INTO `varer` VALUES (4, 2, 'testvare4');

Reply With Quote
  #3  
Old August 25th, 2004, 02:02 AM
cjp_qld cjp_qld is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 1 cjp_qld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Mr Bonds - Did this work?

Hello Mr Bonds. I am trying to do much the same and wondering if "dejbjerg's" solution worked? My database tables will eventually continue to grow, so I don't hard coding will be any good - the best way is from the MySql tables, such as:
MAKER

makeID makeName
Ford 1
Pontiac 2
Chevrolet 3
Hyundai 4

MODELS

modelName model_ID makeID
Escort 1 1
Mustang 2 1
Firebird 6 2
Camaro 1 3
Elantra 3 4


I would appreciate any help with code to solving this. Many thanks.
cjp_qld

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Double drop down in page php using data from mysql (recall)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT