I’ve got the strangest problem. Basically, all my sales scripts are identical in code between the backend and public. The strange part is catagory code works on the public side, but not the admin/backend. The only difference is that the public has a WHERE clause the query.
query:
[php]
$qry_a = mysql_query(
“SELECT start_date, end_date
FROM venzo_itunes_sales
GROUP BY start_date, end_date
ORDER BY start_date”
) or die(mysql_error());
[/php]
diplay code
[php]
<?php $sub = array(); $sub[] = "";
while($r = mysql_fetch_array($qry_a)) {
$tm = explode('/', $r['start_date']);
$yr = $tm[2];
$dte = $r['start_date']. " - " .$r['end_date'];
if($prev_yr != $yr) {
$sub[] = "<optgroup label='$yr'>";
$prev_yr = $yr;
}
$sub[] .= "<option value='$dte'>$dte</option>";
if($prev_yr != $yr) {
$sub[] = "</optgroup>";
$prev_yr = $yr;
}
}
$sub[] = "</select>";
for($k = 0; $k < count($sub); $k++) {
echo $sub[$k];
}
?>
I’m trying to sort it by the year, so it’ll look like
2012
range 1
range 2
2011
range 1
range 2
2010
range 1
range 2
2009
range 1
range 2
and so on.
I’ve never had to use optgroup within a loop before, actually i’ve never used it all. All the examples that i can find on the net are object based, and i don’t understand any of that and don’t have time to completely rewrite the scripts.
If anyone can point me in the right direction or can see what i’m doing wrong, i’d grealty appreciate it.