Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Populate Html Select with MySQL data.

Populate Html Select with MySQL data.

Populate Html Select with MySQL data.


I have a MySQL database which looks like this:

CODE -->

ID             | NAME            | DESCRIPTION                     | DRESSINGS
ham_and_cheese | Ham and Cheese  | A sandwich with ham and cheese  | Mayonnaise, Salad Cream, Chutney, No Dressing
tuna_mayo      | Tuna Mayonnaise | A sandwich with tuna mayonnaise | Water Cress, Pesto 

I need to loop through each record in the database and then populate a select element with the different dressings.
For example:

For ham_and_cheese, it would get the select element with the id "ham_and_cheese_dressings" and then the different options in that select would be "Mayonnaise", "Salad Cream", "Chutney" and "No Dressing".

I'm not very familiar with getting MySQL data and displaying it client side, how would I go about doing this?

Hope this is of use, Rob.yoda

RE: Populate Html Select with MySQL data.

having the dressings as a comma separated list for each record makes it little harder.

However, you need to define how you are displaying things currently. do you want to build a select element for each sandwich?

How are you displaying the sandwiches?

The most straight forward way to do this would be top explode the dressings into an array and loop through it as you display your sandwiches to build the select boxes.



$dressingarray = explode(",",$row['dressings']);
$slectHTML = "<select name='dressings'>";
foreach($dressingarray as $key => $item)
$selectHTML ="<option value='" . $item . "'>" . $item . "</option>";
} $selectHTML = "</select>";
Without any code, its hard to be any more specific.

Phil AKA Vacunita
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close