Group by flere felter - virker ikke efter hensigten
Godaften eksperter..Jeg er i gang med at forsøge at udarbejde et budget/resultat-skema og det ser ud som følgende: http://www.valuable.dk/eksperten/budget/
Jeg har forsøgt at vise problemet ved at man kan vælge at gruppere resultaterne ud fra enten "gruppe" eller "kategori". Jeg vil gerne ha' lavet således at der er grupperet ud fra den overordnede kategori. Problemet er bare at når jeg forsøger at gøre det, så bliver "pengene" smidt sammen til ét felt :/ Jeg har forsøgt ved at lave "GROUP BY" ud fra flere felter, men desværre uden held..
Spørgsmålet er derfor: Hvordan får jeg adskilt "pengene" i kategori-visningen?
Mine tabeller i databasen ser ud som her med følgende relationer:
http://www.valuable.dk/eksperten/budget/dia.jpg
Til at udskrive som jeg gør nu bruger jeg følgende stykke kode:
<table border="1" cellspacing="0" cellpadding="0">
<tr bgcolor="#ECECEC">
<td width="125" height="20" style="padding-left: 5px;"><font color="#155c76">Produktkategori</font></td>
<td width="50" height="20" align="center"><font color="#155c76">JAN</font></td>
<td width="50" height="20" align="center"><font color="#155c76">FEB</font></td>
<td width="50" height="20" align="center"><font color="#155c76">MAR</font></td>
<td width="50" height="20" align="center"><font color="#155c76">APR</font></td>
<td width="50" height="20" align="center"><font color="#155c76">MAJ</font></td>
<td width="50" height="20" align="center"><font color="#155c76">JUN</font></td>
<td width="50" height="20" align="center"><font color="#155c76">JUL</font></td>
<td width="50" height="20" align="center"><font color="#155c76">AUG</font></td>
<td width="50" height="20" align="center"><font color="#155c76">SEP</font></td>
<td width="50" height="20" align="center"><font color="#155c76">OKT</font></td>
<td width="50" height="20" align="center"><font color="#155c76">NOV</font></td>
<td width="50" height="20" align="center"><font color="#155c76">DEC</font></td>
<td width="60" height="20" align="center"><font color="#155c76">Total</font></td>
</tr>
<?php
if ($_GET['g'] == 'gruppe'){
$query = mysql_query("SELECT *, tbl_productcategory.Name as produktkategori, tbl_productgroup.Name as produktgruppe, SUM(tbl_transactions.TotalPrice) AS pris
FROM tbl_productgroup
INNER JOIN tbl_productcategory ON tbl_productcategory.ProductCategoryID = tbl_productgroup.ProductCategoryID
INNER JOIN tbl_product ON tbl_product.ProductGroupID = tbl_productgroup.ProductGroupID
INNER JOIN tbl_transactions ON tbl_transactions.ProductID = tbl_product.ProductID
WHERE Temp = 0 GROUP BY tbl_productgroup.ProductGroupID
") or die(mysql_error());
}
else if ($_GET['g'] == 'kategori'){
$query = mysql_query("SELECT *, tbl_productcategory.Name as produktkategori, tbl_productgroup.Name as produktgruppe, SUM(tbl_transactions.TotalPrice) AS pris
FROM tbl_productgroup
INNER JOIN tbl_productcategory ON tbl_productcategory.ProductCategoryID = tbl_productgroup.ProductCategoryID
INNER JOIN tbl_product ON tbl_product.ProductGroupID = tbl_productgroup.ProductGroupID
INNER JOIN tbl_transactions ON tbl_transactions.ProductID = tbl_product.ProductID
WHERE Temp = 0 GROUP BY tbl_productgroup.ProductCategoryID
") or die(mysql_error());
}
while ($row = mysql_fetch_assoc($query)) {
echo '<tr>';
echo '<td width="125" height="20" style="padding-left: 5px;">' . $row['produktkategori'] . '</td>';
if($row['BudgetMonth'] == 1){
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
}
if($row['BudgetMonth'] == 2){
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
}
if($row['BudgetMonth'] == 3){
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
}
if($row['BudgetMonth'] == 4){
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
}
if($row['BudgetMonth'] == 5){
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
}
if($row['BudgetMonth'] == 6){
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
}
if($row['BudgetMonth'] == 7){
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
}
if($row['BudgetMonth'] == 8){
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
}
if($row['BudgetMonth'] == 9){
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
}
if($row['BudgetMonth'] == 10){
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
}
if($row['BudgetMonth'] == 11){
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
echo '<td width="50" height="20" align="center">0</td>';
}
if($row['BudgetMonth'] == 12){
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">0</td>';
echo '<td width="50" height="20" align="center">'.$row['pris'].'</td>';
}
echo '<td width="60" height="20" align="center">0</td>';
echo '</tr>';
}
?>
<tr bgcolor="#ECECEC">
<td width="125" height="20" style="padding-left: 5px;"><font color="#155c76">I alt</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="50" height="20" align="center"><font color="#155c76">0</font></td>
<td width="60" height="20" align="center"><font color="#155c76">0</font></td>
</tr>
</table>
Håber ikke ovenstående blev betragtet som spam.. Det var blot for at give så mange oplysninger med som der kunne være nødvendigt for at få hjælp - er nemlig helt på herrens mark med det her :/
