greencoin Posted June 15, 2007 Share Posted June 15, 2007 Was just foolin around with some code I have and thought it would be cool to query a database to populate a dropdown box but the option value is not the same as the option content. So I changed my query to individually grab the columns I needed with this; $query = 'SELECT mcode, manu FROM gcmanu'; but now I'm stuck cause I don't know how to grab the individual variables, col1, col2. I could make it work using two queries but I understand that's not the preferred way as it double database traffic. Any advice is appreciated. Thanks ~Rich Link to comment https://forums.phpfreaks.com/topic/55746-solved-query-select-col1-col2-from-table-how-do-i-access-the-columns/ Share on other sites More sharing options...
pocobueno1388 Posted June 15, 2007 Share Posted June 15, 2007 <?php $query = 'SELECT mcode, manu FROM gcmanu'; $result = mysql_query($query); echo '<select name="name">'; while ($row = mysql_fetch_assoc($result)){ echo '<option value="'.$row['mcode'].'">'.$row['gcmanu'].'</option>'; } echo '</select>'; ?> That will give you a populated drop down box where the value will be whatever is in "mcode" and the displayed option will be whatever is in "gcmanu". I wasn't really clear on how you exactly wanted it...so let me know if that is what you wanted. Link to comment https://forums.phpfreaks.com/topic/55746-solved-query-select-col1-col2-from-table-how-do-i-access-the-columns/#findComment-275415 Share on other sites More sharing options...
greencoin Posted June 15, 2007 Author Share Posted June 15, 2007 well, I modified my code using what you gave me and I get a drop down box that drops a long ways but has nothing in it. I'm using godaddy hosting with mysql 4.1. ** corrected - I created a product using the "blank" dropdown and on my query the field was filled in with a value so I'm thinkin there's something to the quotes where the option text would go....the value part is fine. ** corrected, corrected: your quotes were fine, I was using the wrong field name.. :-X Thanks again ~Rich Link to comment https://forums.phpfreaks.com/topic/55746-solved-query-select-col1-col2-from-table-how-do-i-access-the-columns/#findComment-275489 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.