questions

Fetch data into many dropdown button in WP

Rate this post
<?php
global $wpdb;
$result = $wpdb->get_results( "SELECT name FROM student_reg");
foreach ($result as $row){
    echo "<select name='name'>";
    echo "<option value='" . $row->name . "'>" . $row->name . "</option>";
    echo "</select>";
}
?>

This code fetch into many dropdown button not in one button. I want to fetch it into one dropdown button only. Anyone help me?

 

✔️Solution:

Try like this:

<?php
global $wpdb;
$result = $wpdb->get_results( "SELECT name FROM student_reg");
echo "<select name='name'>";
foreach ($result as $row) {
   echo "<option value='" . $row->name . "'>" . $row->name . "</option>";
}
echo "</select>";
?>

Leave a Reply

Your email address will not be published.

Back to top button