Issue
Hey guys i'm stuck on this question. What I'm trying to do is retrieve some data from MYSQL and store it in an option tag. Here is my code.
<?php
$user = "admin";
$password = "";
$db = "test";
$host = "localhost";
$cxn = mysqli_connect($host, $user, $password, $db);
$query = "SELECT ARTIST FROM music";
$results = mysqli_query($cxn, $query) or die("Connection could not be established");
echo "<select name='mediaType'>";
while ($row = mysqli_fetch_assoc($results))
{
extract($row);
echo "<option value=''>$row</option>\n";
}
echo "</select>";
?>
After preforming this function the output in the option tag is "Array" for all options in the select element. I tried storing the data from the php variable $row into an array then looping threw that array and echoing out each index in the array, but the results were the same. May someone plz provide me some guidance on this issue. Thanks all who help.
Solution
Why not simply do:
echo "<select name='mediaType'>";
while ($row = mysqli_fetch_assoc($results))
{
echo "<option value='".$row['ARTIST']."'>".$row['ARTIST']."</option>";
}
echo "</select>";
Answered By - Parag Tyagi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.