MySQL Forums
Forum List  »  PHP

May be you could help me (drop down menu +mysql)
Posted by: Jos Garcia
Date: September 08, 2005 10:27AM

Hello all. Excuse me if the query is so basic. I am writing a script that allows me to take data from a table myql to a lists drop down form to allow to select a product finally and to show its characteristics (not images) and a Link that will be made up of a fixed URL + a code of product (Web Part naumber) to enter to its corresponding webpage.
May be, somebody can help me to follow this?
Now.. how can I show the rest of the data of the model on the same or another page? I'm asking you because it is not passing the variables to the other php.



Many thanks in advance!!!

Jos



Im transcribing the code:


<?PHP
$Host = "";
$User = "";
$Passwd = "";
$DBName = "";
$TableName = "";

$Link = mysql_connect($Host, $User, $Passwd) or die("Could not connect: " . mysql_error());

$Query = "SELECT Distinct manufacturer "."FROM ".$TableName;
$Result = mysql_db_query( $DBName, $Query, $Link );
?>
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
<!--
function BodyLoad() {
var select = document.FormName.manufacturer;
select.options[0] = new Option("Choose One");
select.options[0].value = 0;
<?PHP
$ctr = 1;
While( $Row = mysql_fetch_array($Result) ) {
echo "select.options[" . $ctr . "] = new Option(\"" . $Row["manufacturer"] . "\");\n";
echo "select.options[" . $ctr . "].value = \"" . $Row['model'] . "\";\n";
$ctr++;
}
?>
}

function Fill_Sub() {
var main_select = document.FormName.manufacturer;
var sub_select = document.FormName.model;
if( main_select.options[main_select.selectedIndex].value != 0 ) {
sub_select.length = 0;
}
<?PHP
$Query = "SELECT Distinct manufacturer "."FROM ".$TableName;
$Result = mysql_db_query( $DBName, $Query, $Link );

while( $Row = mysql_fetch_array($Result) ) {
?>
if( main_select.options[main_select.selectedIndex].text == "<?PHP echo $Row[manufacturer]; ?>" ) {
<?PHP
$Query2 = "SELECT manufacturer, model, prefix, webpartnumber, suffix, lamptype, wattage, lamphours, display, trade ".
"FROM $TableName " .
"WHERE manufacturer = '$Row[manufacturer]' ";
$Result2 = mysql_db_query( $DBName, $Query2, $Link );

$ctr = 0;
While( $Row2 = mysql_fetch_array($Result2) ) {
echo "sub_select.options[" . $ctr . "] = new Option(\"" . $Row2["model"] . "\");\n";
echo "sub_select.options[" . $ctr . "].value = \"" . $Row['model'] . "\";\n";
$ctr++;
}

?>
}

<?PHP
}

$manufacturer = $Row2['manufacturer'];
$model = $Row2['model'];
$prefix = $Row2['prefix'];
$webpartnumber = $Row2['webpartnumber'];
$suffix = $Row2['suffix'];
$lamptype = $Row2['lamptype'];
$wattage = $Row2['wattage'];
$lamphours = $Row2['lamphours'];
$display = $Row2['display'];
$trade = $Row2['trade'];

mysql_close($Link);
?>
}
-->
</SCRIPT>

</HEAD>
<BODY onload="BodyLoad();">

<FORM name="FormName" method="POST" action="http://www.hotav.uk.com/testdemo/testdemo2.php">;
<TABLE border="1">
<TR>
<TD>Manufacturer</TD>
<TD>Model</TD>
</TR>
<TR>
<TD>
<SELECT name="manufacturer" onchange="Fill_Sub();"></SELECT>
</TD>

<TD>
<SELECT input name="model" onchange="this.form.submit()"></SELECT>
</TD>
</TR>
</TABLE>
<input type="hidden" name="manuf" value="<?php $_POST['manufacturer'] ?>" />
<input type="hidden" name="mod" value="<?php $_POST['model'] ?>" />
<input type="hidden" name="prefix" value="<?php $_POST['prefix'] ?>" />
<input type="hidden" name="webpartnumber" value="<?php $_POST['webpartnumber'] ?>" />
<input type="hidden" name="suffix" value="<?php $_POST['suffix'] ?>" />
<input type="hidden" name="lamptype" value="<?php $_POST['lamptype'] ?>" />
<input type="hidden" name="wattage" value="<?php $_POST['wattage'] ?>" />
<input type="hidden" name="lamphours" value="<?php $_POST['lamphours'] ?>" />
<input type="hidden" name="display" value="<?php $_POST['display'] ?>" />
<input type="hidden" name="trade" value="<?php $_POST['trade'] ?>" />
</FORM>
</BODY>
</HTML>

Options: ReplyQuote


Subject
Written By
Posted
May be you could help me (drop down menu +mysql)
September 08, 2005 10:27AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.