Grouping results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello All,
How can I group database results in a foreach loop?
I have a field_group column that can have a value or not.

I want to read from the database then display results and if the results have a matching field_group, I want to have them group in the html.

This is my current SQL. I am using MySQL.

$Sql = "SELECT * FROM ".table_name.' GROUP BY Field_ID, Field_Group';

From this I want to be able to wrap the groups in a div and add a h3 with the group name.
So if there are 5 entries in the BOB group, then the html would look like this.

<input name="Field_Name1" />//empty Field_Group
<div id="BOB">//Field_Group = BOB
	<input name="Field_Name2" />
	<input name="Field_Name3" />
	<input name="Field_Name4" />
	<input name="Field_Name10" />
</div>
<input name="Field_Name5" />//empty Field_Group
<input name="Field_Name6" />//empty Field_Group
<div id="Charlie">//Field_Group = Charlie
	<input name="Field_Name8" />
	<input name="Field_Name9" />
	<input name="Field_Name15" />
</div>

Am I setting this up right?  

TIA

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com




[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux