so i have a question regarding, hmmm filtering data in mysql/php.
So i have table lets say
ID | fk1 | fk2
1 1 1
2 1 2
3 1 3
4 2 1
5 2 2
6 3 3
Basicaly i have in same table many occurancies of fk1 that are referenced to fk2 and when i output that in table ofcourse i get result as
1 1
1 2
1 3
2 1
etc. And that is normal. What i want to do is basically output one time FK2 value lets say 1, and all corresponding FK1 values below it. Sorta like group by but for each occurancie of FK2 i need all the FK1s that have that FK2 in their row.
I managed to get it working somehow so that all FK1 print out and corresponding FK2 but other way around wont work :S
$FK1 = '';
while($row = mysql_fetch_array($result_set)){
if($FK1 != $row['fk1']){
if($FK1 != ''){
echo $printout;
}
$FK1 = $row['fk1'];
$printout = "<tr class='success'><td>" . "<strong>" . $row['fk1']. "</td></tr>";
}
$printout = $printout .'<td class="warning"> '.$row['fk2']. '</td></tr>';
}
echo $printout ;
Any idea how to do this with some smart loop instead of using multiple queries on base? Thanks
FK2first andFK1second within your query already, and then implement what’s called a “control break” when outputting the data. en.wikipedia.org/wiki/Control_break