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:<br />
<select name="Var1">
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
<option value="January">January</option>
</select>:<br />
Select Market:<br />
<select name="Var2">
<option value="Good">Good</option>
<option value="Bad">Bad</option>
<option value="Ugly">Ugly</option>
</select>:<br />

<?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>
Member Avatar for diafol

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 ;)

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!

commented: idiot! -1

lol nobody's gonna help you with that attitude

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, $_GET. But, this is stupid method and you need to do some javascript tricks. It is non-sense ! Use the FORM.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.