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, 08: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, 08: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, 01: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
  #4  
Old June 24th, 2009, 12:28 AM
princesam princesam is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 1 princesam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 0
the code above gives following error

'; $q = mysql_query("SELECT * FROM grupper"); echo""; $q2 = mysql_query("SELECT * FROM varer WHERE vare_gruppe_id = $id"); echo""; ?>

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




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek