sonicslp Posted March 11, 2010 Share Posted March 11, 2010 I'm a bit of a newbie here, so I'll try to be thorough. TABLE: ProductGroupsLineItem Fields: ItemID_t, Group_t, SubGroup_t, Brand_t, Active_n Example data: CL2000, Braking, Control Arms, MyBrand, 1 CL3000, Braking, Braded Cables, MyBrand, 1 CL4000, Custom Gauges, Blue, MyBrand, 1 CL5000, Braking, Fluid, MyBrand, 1 Result I would like: Group_t = Braking Group_t = Custom Gauges I only have "SubGroup_t" when starting. First I find all "ItemID_t" that contain the correct "SubGroup_t" value. Then, I find all "Group_t" from that result. Ultimately, I just want to find every possible group from that result, but I only want to display one of each group. What I'm getting with the query below is: Group_t = Braking Group_t = Braking Group_t = Custom Guages Group_t = Braking I use "Group By" in other places and it works great, I assume it has something to do with the nested "while"? $r1 = mysql_query("SELECT ItemID_t FROM ProductGroupsLineItem WHERE Brand_t='$MFGNAME' AND SubGroup_t='$subgroup'"); while ($row1 = mysql_fetch_array($r1)) { $ItemID = $row1['ItemID_t']; $r2 = mysql_query("SELECT Group_t FROM ProductGroupsLineItem WHERE Brand_t='$MFGNAME' AND ItemID_t='$ItemID' AND Active_n='1' GROUP BY Group_t ORDER BY Group_t ASC") or die(mysql_error()); while ($row2 = mysql_fetch_array($r2)) { $groupGeneral = $row2['Group_t']; echo $groupGeneral; echo '<br />'; } } Link to comment https://forums.phpfreaks.com/topic/194856-cant-get-group-by-to-work/ Share on other sites More sharing options...
sonicslp Posted March 11, 2010 Author Share Posted March 11, 2010 Is my explanation too confusing? I'm really stumped here. Link to comment https://forums.phpfreaks.com/topic/194856-cant-get-group-by-to-work/#findComment-1024879 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.