954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Drop Down Dilema!

This simple query is proving to be a problem for me as I'm missing something obvious.

Its a query to show Sales by Market ($var2) by Month ($var1).

Any pointers as to what I'm doing wrong.

<html> 
<head><title>Monthly Sales Rank </title>
<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>
<script src="sorttable.js"></script>
</head> 
<body> 
Select Month:
<select name="Var1">
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
<option value="January">January</option>
</select>:
Select Market:
<select name="Var2">
<option value="Good">Good</option>
<option value="Bad">Bad</option>
<option value="Ugly">Ugly</option>
</select>:

<?php
set_time_limit(0);
error_reporting (E_ALL ^ E_NOTICE);

include 'db.php';
$Mnth = $_POST["Var1"];
$Mkt = $_POST["Var2"];

$result = mysql_query('
Select 
MonthName(OrderDate),
Sum(OrderedQuantity) As Ordered, 
Round(Avg(Price),2) As AvgSellPrice, 
Round(Avg(Shipping),2) As AvgShipping, 
MarketName
From Mydb
where MonthName(OrderDate) = "$Mnth" and Market = "$Mkt"
Group By Market, MonthName(OrderDate)
with rollup
') 
or die("SELECT Error: ".mysql_error()); 
$num_rows = mysql_num_rows($result); 
print "Click on column name to sort. Totals now showing. More options at end <P>"; 
print "<table class='sortable' width=800 border=1>\n"; 
echo "<tr> <th>Title</th> <th>Ord Qty</th> <th>Avg Sales Rank</th> <th>£ Min</th> <th>£ Max</th> <th>£ Average</th> <th>Market</th> </tr>";
while ($get_info = mysql_fetch_row($result)){ 
print "<tr>\n"; 
foreach ($get_info as $field) 
print "\t<td><font face=arial size=2/>$field</font></td>\n"; 
print "</tr>\n"; 
} 
print "</table>\n"; 
?> 

</body> 
</html>
eman neercs
Newbie Poster
11 posts since Nov 2009
Reputation Points: 9
Solved Threads: 0
 

Your form isn't a form.
You haven't submitted the form, so $_POST['..'] do not exist.
If they don't exist, you can't use them in the query ;)

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Doh!

Going to split it between a form (htm) and the search arguments (php) which I've used elsewhere.

Strange how you can convince yourself your almost right when you're miles off!

eman neercs
Newbie Poster
11 posts since Nov 2009
Reputation Points: 9
Solved Threads: 0
 

lol nobody's gonna help you with that attitude

vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 

You need to wrap FORM. Otherwise, use GET method to pass those values with ((param1=value1&param2=value2) separating ampersand between them) via URL to the page you want to process. Then, you can retrieve $_GET['param1'], $_GET['param2']. But, this is stupid method and you need to do some javascript tricks. It is non-sense ! Use the FORM.

Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: