thomashw Posted January 9, 2008 Share Posted January 9, 2008 In this following code, you'll notice there are two $form['feature_group_name'] and two $form['feature_item_name']. <? $query = mysql_query(" SELECT feature_product.feature_product_id, feature_product_name, feature_product_price, feature_group.feature_group_id, feature_item.feature_group_id, feature_group_name, feature_item_name, feature_item_price FROM feature_product, feature_group, feature_item WHERE feature_product.feature_product_id={$id} AND feature_group.feature_product_id=feature_product.feature_product_id AND feature_item.feature_group_id=feature_group.feature_group_id"); echo "<tr>\n<td>\n<label><span>"; $count==0; while($form = mysql_fetch_array($query)) { if($count==0) { echo $form['feature_group_name'] . ':'; echo "</span>\n</label>\n</td\n<td align=\"left\" width=\"57%\" class=\"productdrop\">\n<select name=\"cat1\">"; echo '<option value="' . $form['feature_group_name'] . ':' . $form['feature_item_name'] . '">' . $form['feature_item_name'] . '</option>'; ++$count; }} echo "</select>\n</td>\n</tr>\n<br />"; ?> The first $form['feature_group_name'] is displayed as field_name in the following image (it's just some text.) The $form['feature_item_name'] are the actual options in the dropdown boxes. In my database, there are multiple options per "field_name" for the dropdown boxes, as well as multiple "field_names" (as shown in the image.) I need the <option></option> field for the first dropdown box to loop until all $form['feature_item_name'] fields are used up for that specific $form['feature_group_name'] (field_name in the image.) Then I need the whole thing to move on (loop) to the next dropdown box (and field_name.) Basically, I need the part in the <option></option> area to loop until all the $form['feature_item_name'] are used up, and then I need the whole thing to echo to create the second drop down box along with its "field_name." Does this make sense, or did I overcomplicate my explanation? Anyways, the way I've done it it isn't going to loop properly. I was wondering if someone could help. Quote Link to comment https://forums.phpfreaks.com/topic/85145-solved-need-a-bit-of-help/ Share on other sites More sharing options...
GingerRobot Posted January 9, 2008 Share Posted January 9, 2008 Well, firstly, you need to be ordering by the groups. You can then cycle through the results, outputing a new select box if the group name of the current row is different to the last row's group name. Try: <?php $query = mysql_query(" SELECT feature_product.feature_product_id, feature_product_name, feature_product_price, feature_group.feature_group_id, feature_item.feature_group_id, feature_group_name, feature_item_name, feature_item_price FROM feature_product, feature_group, feature_item WHERE feature_product.feature_product_id={$id} AND feature_group.feature_product_id=feature_product.feature_product_id AND feature_item.feature_group_id=feature_group.feature_group_id ORDER BY feature_group_name") or die(mysql_error()); $curr = ''; while($row = mysql_fetch_assoc($query)){ if($curr != $row['feature_group_name']){//last group isn't the same as the current one if($curr != ''){//we're not on the first iteration of the loop - end the last select box echo "</select> <br />\n"; } //output the new select box echo '<select="'.$row['feature_group_name'].'">';//not sure what name you wanted the select boxes to have? $curr = $row['feature_group_name'];//update the current group } //output the option for this row echo '<option value="'.$row['feature_group_name'].':'.$row['feature_item_name'] . '">'.$row['feature_item_name'] ."</option>\n"; } echo "</select><br />\n"; ?> You'll need to format the layout a bit, and you might need to change the names of the select boxes/options - i wasn't entirely sure what you wanted. Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/85145-solved-need-a-bit-of-help/#findComment-434413 Share on other sites More sharing options...
thomashw Posted January 9, 2008 Author Share Posted January 9, 2008 You're awesome. I'll give that a go and report back! Quote Link to comment https://forums.phpfreaks.com/topic/85145-solved-need-a-bit-of-help/#findComment-434548 Share on other sites More sharing options...
thomashw Posted January 9, 2008 Author Share Posted January 9, 2008 I notice you took out all the table stuff - is it better to do it without? Quote Link to comment https://forums.phpfreaks.com/topic/85145-solved-need-a-bit-of-help/#findComment-434565 Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 That depends on you and how you do your layout. Some like tables, some don't. Quote Link to comment https://forums.phpfreaks.com/topic/85145-solved-need-a-bit-of-help/#findComment-434576 Share on other sites More sharing options...
thomashw Posted January 9, 2008 Author Share Posted January 9, 2008 Ahh, okay. I use div's as much as I can, but usually for something like this it's much easier to get everything to line up with a table. It's not "bad" to use tables for content, is it? Quote Link to comment https://forums.phpfreaks.com/topic/85145-solved-need-a-bit-of-help/#findComment-434577 Share on other sites More sharing options...
nikefido Posted January 9, 2008 Share Posted January 9, 2008 Ahh, okay. I use div's as much as I can, but usually for something like this it's much easier to get everything to line up with a table. It's not "bad" to use tables for content, is it? def not "bad" - whatever works, works! forums like this still use tables because it's the best approach that works well. Quote Link to comment https://forums.phpfreaks.com/topic/85145-solved-need-a-bit-of-help/#findComment-434578 Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 Once you learn CSS, you'll never use tables again. Quote Link to comment https://forums.phpfreaks.com/topic/85145-solved-need-a-bit-of-help/#findComment-434580 Share on other sites More sharing options...
thomashw Posted January 9, 2008 Author Share Posted January 9, 2008 My site uses quite a bit of CSS - using CSS, how could you make everything line up properly like this? Quote Link to comment https://forums.phpfreaks.com/topic/85145-solved-need-a-bit-of-help/#findComment-434582 Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 Using positions. Quote Link to comment https://forums.phpfreaks.com/topic/85145-solved-need-a-bit-of-help/#findComment-434583 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.