Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-01-2012, 01:23 AM   PM User | #1
penny94
New Coder

 
Join Date: Sep 2012
Posts: 21
Thanks: 3
Thanked 0 Times in 0 Posts
penny94 is an unknown quantity at this point
Populate HTML Drop Down Box From MySQL Data

Edit: Solved!

PHP Code:
$query "SELECT DISTINCT category FROM browse"
--------------------------


I have a piece of code that gets data from my MySQL Table and puts it into a drop down box. It works great. However I don't want it to duplicate rows.

For example some things in the table have the same category and at the moment it displays the category multiple times in the drop down box.

How can I avoid this?


PHP Code:

Select a category: <select id="dropdown" name="cat">
  <?php
include 'config.inc';
$query "SELECT * FROM browse";
$result mysql_query($query) or die (mysql_error());
while(
$row mysql_fetch_array($result)) {



?><option><?php echo $row['category']; ?></option>
<?php
}
?>
</select>

Last edited by penny94; 11-01-2012 at 03:14 AM..
penny94 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:59 AM.


Advertisement
Log in to turn off these ads.