Still no joy with this. It's a very long page of code with multiple dropdowns and i just can't figure the correct way to deploy them and the postback requirements.
Basically i need it to display the contents of FormatName (from the Format table) in the first dropdown. When the user chooses and hits the select button, it should show the style dropdown (populated from the Style table). Likewise when the user chooses a Style, they should then be shown the Size dropdown (populated by the Size table).
As each item is chosen it should be printed separately underneath using the print statements.
Finally under that it should use the 3 selected pieces of data to calculate the price (from the Price table)
I have commented out some of the POST code at the top as it refuses to work and i've added in definition of StyleID,StyleName,SizeID .. etc etc otherwise they are not recognised.
All of my linking and select statements seem to work fine, but these dropdowns have me stumped.
Any suggestions appreciated.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" href="Test.css" type="text/css" />
<script language="JavaScript">
<!--
function submitform(form)
{
Paintingform.postback.value = "posted";
form.submit();
}
//-->
</script>
</head>
<body>
<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
$CategoryID=$_GET["CategoryID"];
$CategoryName=$_GET["CategoryName"];
$GroupID=$_GET["GroupID"];
$Group=$_GET["Group"];
$ManufacturerID=$_GET["ManufacturerID"];
$ManufacturerName=$_GET["ManufacturerName"];
$ManufacturerCategoryID=$_GET["ManufacturerCategoryID"];
$PaintingID=$_GET["PaintingID"];
//$PaintingName=$_GET["PaintingName"];
echo "Microsoft.Jet.OLEDB.4.0";
$conn=mysql_connect("localhost","XXXX","XXXX");
mysql_select_db("XXXX",$conn);
$Style = ("Style");
$StyleID = ("StyleID");
$StyleName = ("StyleName");
$SizeID = ("SizeID");
$SizeName = ("SizeName");
$FormatID = ("FormatID");
$FormatName = ("FormatName");
//$PaintingName =("PaintingName");
$ImgName = ("ImgName");
$Price = ("Price");
/*
if ($_POST["Format"]!="")
{
$formatID=$_POST["Format"];
}
if ($_POST["Style"]!="")
{
$styleID=$_POST["Style"];
}
if ($_POST["Size"]!="")
{
$SizeID=$_POST["Size"];
}
*/
if ($_GET["PaintingID"]=="")
{
$PaintingID=$_POST["PaintingID"];
}
else
{
$PaintingID=$_GET["PaintingID"];
}
// $rs is of type "ADODB.recordset"
$rs=mysql_query("SELECT Paintings.PaintingID, Paintings.PaintingName, Paintings.ManufacturerCategoryID, Paintings.ImgName, Paintings.Price, Paintings.GroupID FROM Paintings WHERE Paintings.PaintingID = '".$PaintingID."'");
$PaintingName =("PaintingName");
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" cool gridx="8" gridy="8" showgridx showgridy usegridx usegridy><tr height="8"><td align="center"><img src="images/CGLLogoSmall.jpg"></td></tr></table>
<hr />
<br />
<?php $row = mysql_fetch_array($rs) ?>
<table align="center">
<tr>
<td align="center" class="heading"><a href="Gallery.php" class="heading">Gallery</a> - <a href="Group.php?Group=<?php print $Group;?>&GroupID=<?php print $GroupID;?>" class="heading"><?php print $Group;?> Prints</a> - <a href="Categories.php?CategoryID=<?php print $CategoryID;?>&CategoryName=<?php print $CategoryName;?>&Group=<?php print $Group;?>&GroupID=<?php print $GroupID;?>&ManufacturerID=<?php print $ManufacturerID;?>&ManufacturerName=<?php print $ManufacturerName;?>&ManufacturerCategoryID=<?php print $ManufacturerCategoryID;?>" class="heading">
<?php print $ManufacturerName;?></a> - <a href="Paintings.php?CategoryID=<?php print $CategoryID;?>&CategoryName=<?php print $CategoryName;?>&Group=<?php print $Group;?>&GroupID=<?php print $GroupID;?>&ManufacturerID=<?php print $ManufacturerID;?>&ManufacturerName=<?php print $ManufacturerName;?>&ManufacturerCategoryID=<?php print $ManufacturerCategoryID;?>" class="heading"><?php print $CategoryName;?></a> - <?php print $row['PaintingName']; ?></td></tr>
</table>
<br /><br />
<table align="center" border="0">
<tr><td width="250px" align="left"><img src="images/<?php print $row['ImgName'];?>-large.gif" border="0" /></td>
<td valign="top" align="left">
<strong><?php print $row['PaintingName'];?></strong><br /><br />
<?php print $ManufacturerName;?><br /><br />
<?php print $CategoryName;?><br /><br />
</td></tr>
<tr><td colspan="2"> </td></tr>
<tr><td colspan="2" valign="bottom" align="left">
</td></tr>
<?php
mysql_close($conn);
?>
</table>
<?php
$conn3=mysql_connect("localhost","XXXX","XXXX");
mysql_select_db("XXXX",$conn3);
$rs3=mysql_query("SELECT PaintingDetail.PaintingDetailID, PaintingDetail.PaintingID, PaintingDetail.FormatID, PaintingDetail.StyleID, PaintingDetail.SizeID, PaintingDetail.Price FROM PaintingDetail WHERE PaintingDetail.PaintingID = ".$PaintingID." ORDER BY PaintingDetail.FormatID");?>
<p class="subheading">Please select the Format, Style and Size below</p>
<form name="Paintingform" method="post" id="Paintingform"><input type="hidden" name="PaintingID" value="<?php if ($_GET["PaintingID"]!="")
{
print $_GET["PaintingID"];
}
else
{
print $_POST["PaintingID"];} ?> " /><input type="hidden" name="postback" value="<?php print $_POST["postback"];?>" /><input type="hidden" name="test" value="<?php print $StyleID;?>" />
<table align="center" width="800px" border="1"><tr><td><table border="0" class="heading" width="100%"><tr><td align="left" width="25%"><strong>Format</strong></td><td align="center" width="25%"><strong>
Style</strong>
</td>
<td align="right" width="25%"><strong>Size</strong></td>
</tr>
<tr><td colspan="4"> </td></tr>
<tr align="left">
<td><select name="Format" onchange="submitform(form)">
<?php
$connformat=mysql_connect("localhost","XXXX","XXXX");
mysql_select_db("XXXX",$connformat);
$rsformat=mysql_query("SELECT DISTINCT PaintingDetail.FormatID as FormatID, PaintingDetail.PaintingID, Format.FormatID, Format.FormatName FROM PaintingDetail, Format WHERE PaintingDetail.FormatID = Format.FormatID AND PaintingDetail.PaintingID = '".$PaintingID."' ORDER BY PaintingDetail.FormatID");
if ($_POST["postback"]=="")
{
if ($rsformat) { //This will check if the query failed or not
if (mysql_num_rows($rsformat) > 0) { //This will check if there were any results returned from the query
while ($row = mysql_fetch_array($rsformat)) {
print "<option value='".$rsformat['FormatID']."'>".$rsformat['FormatName']."</option>";
}
}
}
}
else
{
if ($rsformat)
{
if (mysql_result($rsformat,"FormatID")==$_POST["Format"])
{
print "<option value='".$rsformat['FormatID']."' selected='selected'>".$rsformat['FormatName']."</option>";
$FormatID=mysql_result($rsformat,"FormatID");
$FormatName=mysql_result($rsformat,"FormatName");
}
else
{
print "<option value='".mysql_result($rsformat,"FormatID")."'>".mysql_result($rsformat,"FormatName")."</option>";
}
}
while($row = mysql_fetch_array($rsformat));
}
mysql_close($connformat);
?>
</select>
<input type="button" value="Select" onclick="submitform(form)" /></td><td align="center">
<td><select name="Style" onchange="submitform(form)">
<?php
$connstyle=mysql_connect("localhost","XXXX","XXXX");
mysql_select_db("XXXX",$connstyle);
$rsstyle=mysql_query("SELECT DISTINCT PaintingDetail.StyleID AS StyleID, PaintingDetail.PaintingID, PaintingDetail.FormatID, Style.StyleID, Style.StyleName FROM PaintingDetail, Style WHERE PaintingDetail.StyleID = Style.StyleID AND PaintingDetail.PaintingID = ".$PaintingID." AND PaintingDetail.FormatID = '".$FormatID."' ORDER BY PaintingDetail.StyleID");
If ($_POST["Style"]=="")
{
if ($rsstyle) { //This will check if the query failed or not
if (mysql_num_rows($rsstyle) > 0) { //This will check if there were any results returned from the query
while ($row = mysql_fetch_array($rsstyle)) {
$StyleID=mysql_result($rsstyle,"StyleID");
print "<option value='".$rsformat['StyleID']."'>".$rsstyle['StyleName']."</option>";
}
}
}
}
else
{
//if (!($rsstyle==0))
if(mysql_fetch_row($rsstyle))
{
print "<select name='Style' onchange='submitform(form)'>";
do
{
if (mysql_result($rsstyle,"StyleID")==$_POST["Style"])
{
print "<option value='".mysql_result($rsstyle,"StyleID")."' selected='selected'>".mysql_result($rsstyle,"StyleName")."</option>";
$StyleID=$rsstyle['StyleID'];
$StyleName=$rsstyle['StyleName'];
}
else
{
print "<option value='".mysql_result($rsstyle,"StyleID")."'>".mysql_result($rsstyle,"StyleName")."</option>";
$StyleID=$_POST["Style"];
}
}
while ($row = mysql_fetch_array($rsstyle));
print "</select> <input type='button' value='Select' onclick='submitform(form)' />";
}
else
{
$StyleID="NA";
$StyleName="N/A";
print $StyleName;
}
}
mysql_close($connstyle);
//styleID = request.form("Style")
?>
</select>
<input type="button" value="Select" onclick="submitform(form)" /></td><td align="center">
<td><select name="Size" onchange="submitform(form)">
</td>
<td align="right">
<?php
// $connsize is of type "ADODB.Connection"
$connsize=mysql_connect("localhost","XXXX","XXXX");
mysql_select_db("XXXX",$connsize);
if ($StyleID!="NA")
{
$rssize=mysql_query("SELECT DISTINCT PaintingDetail.SizeID as SizeID, PaintingDetail.PaintingID, PaintingDetail.FormatID, PaintingDetail.StyleID, [Size].SizeID, [Size].SizeName FROM PaintingDetail, [Size] WHERE PaintingDetail.SizeID = [Size].SizeID AND PaintingDetail.PaintingID = ".$PaintingID." AND PaintingDetail.FormatID = '".$FormatID."' AND PaintingDetail.StyleID = '".$StyleID."' ORDER BY PaintingDetail.SizeID");
}
else
{
$rssize=mysql_query("SELECT DISTINCT PaintingDetail.SizeID as SizeID, PaintingDetail.PaintingID, PaintingDetail.FormatID, PaintingDetail.StyleID, [Size].SizeID, [Size].SizeName FROM PaintingDetail, [Size] WHERE PaintingDetail.SizeID = [Size].SizeID AND PaintingDetail.PaintingID = ".$PaintingID." AND PaintingDetail.FormatID = '".$FormatID."'");
{
if ($rssize) { //This will check if the query failed or not
if (mysql_num_rows($rssize) > 0) { //This will check if there were any results returned from the query
while ($row = mysql_fetch_array($rssize)) {
print "<option value='".$rssize['SizeID']."'>".$rssize['SizeName']."</option>";
$SizeID=$rssize['SizeID'];
}
}
}
}
print "<select name='Size' onchange='submitform(form)'>";
do
{
if (mysql_result($rssize,"SizeID")==$_POST["Size"])
{
print "<option value='".mysql_result($rssize,"SizeID")."' selected='selected'>".mysql_result($rssize,"SizeName")."</option>";
$SizeID=$rssize['SizeID'];
$SizeName=$rssize['SizeName'];
}
else
{
print "<option value='".mysql_result($rssize,"SizeID")."'>".mysql_result($rssize,"SizeName")."</option>";
}
}
while(odbc_fetch_row($rssize));
print "</select> <input type='button' value='Select' onclick='submitform(form)' />";
}
mysql_close($connsize);?>
</td>
</tr>
<tr><td colspan="3"> </td></tr>
<?php print "<table width='100%' border='0' class='subheading'><tr><td>";
print "<tr><td width='30%' align='left'> </td><td align='left'>Format:</td>";
if ($FormatName=="")
{
print "<td align='left'>Please select a Format</td><td width='30%'> </td></tr>";
}
else
{
print "<td align='left'>".$FormatName."</td><td width='30%'> </td></tr>";
// print "<td align='left'>".$FormatID."</td><td width='30%'> </td></tr>";
} ?>
<?php print "<tr><td width='30%' align='left'> </td><td align='left'>Style:</td>";?>
<?php if ($StyleName=="")
{
print "<td align='left'>Please select a Style</td><td width='30%'> </td></tr>";
}
else
{
print "<td align='left'>".$StyleName."</td><td width='30%'> </td></tr>";
//print "<td align='left'>".$StyleID."</td><td width='30%'> </td></tr>";
}
?>
<?php print "<tr><td width='30%' align='left'> </td><td align='left'>Size:</td>";?>
<?php if ($SizeName=="")
{
print "<td align='left'>Please select a Size</td><td width='30%'> </td></tr>";
}
else
{
print "<td align='left'>".$SizeName."</td><td width='30%'> </td></tr>";
//print "<td align='left'>".$SizeID."</td><td width='30%'> </td></tr>";
} ?>
<?php print "<tr><td colspan='4'> </td></tr>";?>
<?php
// $connprice is of type "ADODB.Connection"
$connprice=mysql_connect("localhost","XXXX","XXXX");
mysql_select_db("XXXX",$connprice);
if ($StyleID == "NA")
{
$rsprice=("SELECT PaintingDetail.Price, PaintingDetail.SizeID, PaintingDetail.PaintingID, PaintingDetail.FormatID, PaintingDetail.StyleID FROM PaintingDetail WHERE PaintingDetail.PaintingID = ".$PaintingID." AND PaintingDetail.FormatID = '".$FormatID."' AND PaintingDetail.SizeID = '".$SizeID."' ORDER BY PaintingDetail.Price");
}
else
{
$rsprice=("SELECT PaintingDetail.Price, PaintingDetail.SizeID, PaintingDetail.PaintingID, PaintingDetail.FormatID, PaintingDetail.StyleID FROM PaintingDetail WHERE PaintingDetail.PaintingID = ".$PaintingID." AND PaintingDetail.FormatID = '".$FormatID."' AND PaintingDetail.StyleID = '".$StyleID."' AND PaintingDetail.SizeID = '".$SizeID."' ORDER BY PaintingDetail.Price");
}
//if ($_POST["postback"]=="")
//{
//}
// else
{
// if (mysql_fetch_row($rsprice))
//
// {
// $Price=$rsprice['Price'];
//
// }
// else
// {
$Price="crap";
//response.Write("No Price")
}
?>
<?php if ($FormatName=="" || $StyleName=="" || $SizeName=="")
{
}
else
{
print "<tr><td width='30%' align='left'> </td><td align='left'><strong>Price:</strong></td><td align='left'><strong>£".number_format($Price)."</strong></td><td width='30%'> </td></tr>";
//print $sqlprice;
?>
<?php print "</tr></td></table>";?>
<?php
mysql_close($connprice);
} ?>
</table></td></tr></table>
<?php //if request.form("Format") <> "" and request.form("Style") <> "" and request.Form("Size") <> "" then
//response.Write("<br /><input type='button' value='Refresh Price' onclick='submitform(form)' />")
//end if
?>
</form>
<hr />
</body>
</html>
I apologise unreservedly for the length of that, but it seemed best to let you see everything going on in the page than snippets.
Many Thanks
Mikey