fohanlon Posted May 7, 2008 Share Posted May 7, 2008 Hi Guys I have a members table with 3 fields I want to pull back to populate a dynamic drop down. I have something like this: SELECT field1, field2, field3 from members ORDER BY field2, field3 ASC Heres what I want to do. I need to list the results sorted ASC with field2 and field3 merged for example, say field2 has BAD DAD MAM and field2 has CAT ELEPHANT SNAKE I need the result to be listed BAD CAT DAD ELEPHANT# MAM SNAKE Do you see what I mean? What is the mysql code for this? thanks, fergal. Link to comment https://forums.phpfreaks.com/topic/104619-merge-and-sort-two-columns-in-same-table/ Share on other sites More sharing options...
rhodesa Posted May 7, 2008 Share Posted May 7, 2008 It would just be like any example you find out there, except with 2 options in the loop: <?php $result = mysql_query("SELECT field1, field2, field3 from members ORDER BY field2, field3 ASC"); print '<select name="mytest">'; while($row = mysql_fetch_assoc($result)){ print '<option value="'.htmlspecialchars($row['field2']).'">'.htmlspecialchars($row['field2']).'</option>'; print '<option value="'.htmlspecialchars($row['field3']).'">'.htmlspecialchars($row['field3']).'</option>'; } print '</select>'; ?> Link to comment https://forums.phpfreaks.com/topic/104619-merge-and-sort-two-columns-in-same-table/#findComment-535464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.