Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.