0

I want my dropdown-textbox-select(I'm confused what it really is) to query all the data in the appropriate table I want to display. But it is displaying all the data with separated dropdown-textbox-select. I just want the data to be inside. Here's what I'm doing so far.

<?php   


    $sel_admin = "SELECT * FROM author";
    $rs_admin = mysql_query($sel_admin);
    while($row = mysql_fetch_array($rs_admin))
                {
                echo '<select class="form-control">';
                echo"  <option value='volvo'>" . $row['author_firstname'] . $row['author_lastname'] ."</option>";
                echo'</select>';
                }
                ?>

PS. If the user click submit, I want the author_id to be save, instead of the name. How can this be also?

0

1 Answer 1

2

Your select tag should be outside of the while loop : you want only one select field, containing options with all the fetched rows.

echo '<select class="form-control">';
while($row = mysql_fetch_array($rs_admin))
{
    echo"  <option value='volvo'>" . $row['author_firstname'] . $row['author_lastname'] ."</option>";
}
echo'</select>';

If you want to get the author_id from this form, just put this value in the option's value attribute.

echo"  <option value='". $row['author_id'] ."'>" . $row['author_firstname'] . $row['author_lastname'] ."</option>";

Don't forget to give a name to your select tag.

Sign up to request clarification or add additional context in comments.

4 Comments

Hey yes, thank you for that. I'm waiting also for the author_id to be resolved. Glad that you also answer it. Please wait for 5 minutes to be accepted it :)
What's wrong with the author_id? I suggested a solution but maybe I didn't understand what was the issue?
It's originally a book table, and the author is a foreign key. And sorry, for the misunderstanding. Because, you originally answer it without it.
Yes I edited my answer, I missed the 'PS' at first (my fault I should have commented to mention it). :)

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.