php - MySQL: printing data just once for each grouping -
I'm coding in PHP / MySQL and asking the following questions to fetch products and product group data:
Then this query brings the product and orders them through the product group. For each product grouping I only want to show product_groups.name once. So even if I have ten shoes products, the name of the group "shoes" is displayed only once.
I am using the following PHP to print out the results:
while ($ data = mysql_fetch_array ($ result))
If you want to query this MySQL, it's honestly more than its price is a problem, for the syntax really In the Delay (as I remember) the name of the group listed at the top of each group and the results are still explained as rows, so A group name will be treated as a tap with all the other columns, so that you can not save any time or effort in PHP scripts, because it is a statement to hold to hold group name instead of group data. .
If you want it to be loop by PHP, while Johan is on the right track, I use the following for the same situation:
$ result = $ Sql- & gt; Query ($ query); $ Prev_group = ""; While ($ data = $ result-> fetch_assoc ()) {$ curr_group = $ data ['group']; If ($ curr_group! == $ prev_group) {echo " $ curr_group "; $ Prev_group = $ curr_group; } Else {$ echo the data; .....}
Obviously resonant data will be set to resonate the parts of the data you want. But $ prev_group / $ curr_group is set up so that when they are on a new group and want to print any type of header, they will not match that time.
Comments
Post a Comment