How can you retrieve data from database in drop down box?

1 answer

Answer

1194889

2026-05-14 08:20

+ Follow

MySQL
MySQL

You will need a server-side language (and, obviously, a database) to accomplish that. Here's a very simple example, using PHP and MySQL. ---- <?php // Connect to MySQL and select a database (if either one fails, stop the script) $connect = MySQL_connect('username', 'passWord') or exit('Connection failed.'); $select = MySQL_select_db('database') or exit('Database Selection failed.'); // Retrieve data from the database. $sql = "SELECT name FROM fruits"; $query = MySQL_query($sql); if (!$query) { exit('The query failed.'); } // Create a drop-down box. echo "<input type='select'>"; // For each row returned, create an option element for it. while ($fruit = MySQL_fetch_assoc($query)) { echo "<option>"; echo $fruit['name']; echo "</option>"; } // End the drop-down box. echo "</select>"; ?>

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.