0

I have retrieved the database values in dropdown list with multiple select option using PHP MySQL. My code is as follows.

$sql = "SELECT student_id, name, phone FROM student";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

    echo "<select name='num' multiple >";
    while($row = $result->fetch_assoc()) {
       echo "<option value='" . "'>" . $row['name']. " " . $row['phone_number'] ."</option>";
    }
    echo "</select>";




} else {
    echo "0 results";
}

What I need is, I want to post the multiple selected phone_number values to another page. Also, Is it possible to create a checkbox before the list values?

Now am getting the output as in this image.

2
  • Possible duplicate of php multiple select drop down Commented Jun 21, 2017 at 5:08
  • That seems to have manual array values. I need to retrieve the array values from sql.. Commented Jun 21, 2017 at 7:32

1 Answer 1

0

Change this line to :

echo "<select name='num[]' multiple >";

name should be in array format like num[] not like num

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

3 Comments

ok. Thanks for your reply. And how can post only the selected phone_number values to another form? Moreover, Am not getting checkbox before the name or number.
"And how can post only the selected phone_number values to another form? Moreover, Am not getting checkbox before the name or number." where is the code for that ? and you should post another question for this.
echo "<option value='" . "'>" . $row['name']. " " . $row['phone_number'] ."</option>"; In this I want to select a few names and only the selected phone_number corresponding to the names has to be passed into another form or page.

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.