0

I want a html with a dropdown menu were it's items are picked up from a mysql database. Then, when I select one of them, I want to be able to use it on a php file. Anybody has an example? Thanks

2 Answers 2

1
print '<form method="post" action="submit.php">';
print '<select size="1" name="myselect">';
foreach($dbresults as $r) {
    print '<option value="'.$r['field'].'">'.$r['field'].'</option>';
}
print '</select>';
print '<input type="submit" value="Go!" />';
print '</form>';

And on the form's action page:

$chosen_thing = $_POST['myselect'];
Sign up to request clarification or add additional context in comments.

2 Comments

Grim but how can I use foreach($dbresults as $r) { print '<option value="'.$r['field'].'">'.$r['field'].'</option>'; } in html file? isn't that php code?
Yes - so put it in php tags. You can mix HTML and php on the same page (give it a .php extension) - although this isn't 'best practice', I wouldn't worry about that right now.
0

You might want to look into how it's done in commonly used CMS applications, e.g. WordPress, Drupal, Joomla, etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.