Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
below is the code FORM with dynamic drop down list



PHP
<?php
$select_query=          "Select category from books";
$select_query_run =     mysql_query($select_query);
$select_query_array=   mysql_fetch_array($select_query_run) ;
 $cat = $select_query_array['category'];
echo "<select name='category'>";
while ($select_query_array=   mysql_fetch_array($select_query_run) )
{
  echo "<option value='' >".htmlspecialchars($select_query_array["category"])."</option>";
}

echo "</select>";
?>


under category column i have different types of books categories like "fiction,journal,non-fiction, etc". to show this I created dynamic drop down list which will fetch all values under category column from database table. my problem is I am unable to prevent duplication for this. ex: category have four fiction and two journal. my drop down list is also showing four fiction and two journals. I don't want to show like this way for any values I want to show only fiction,journal,non-fiction.
simply I want to prevent duplication is drop down list. please anyone help me....
Posted

 
Share this answer
 
Comments
Member 11406049 19-Feb-15 5:00am    
thank you very much.. and will you help me how to print values based on category?
Try applying distinct in SQL query...

Select distinct category from books
 
Share this answer
 
Comments
Member 11406049 19-Feb-15 4:57am    
thank you very much...
Member 11406049 19-Feb-15 4:59am    
will you please help me how to print based on category?
manak chand 19-Feb-15 5:04am    
Is the code you had mentioned not working .. what issue you are getting...
Member 11406049 19-Feb-15 5:07am    
its working perfectly thank you.
manak chand 19-Feb-15 5:10am    
pls rate my answer if it helps...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900