php - populate drop down list from database using mysqli prepared statements -


as title says want generated data database , show in dropdown. made code , doesn't show error thing echos code in dropdown. works when echo it. , 1 more thing doesn't show distinct results.

here code:

<html> <head> <title>filter</title> </head> <body> <?php include 'conn.php';?>  <?php     $stmt = $con->prepare("select distinct author, book_name, language bk_tst_fltr ");     $stmt->execute();     $stmt->bind_result($author,$book_name,$language);     $stmt->store_result();     echo "<select name='book'>";     while($row=$stmt->fetch()){?>         <p><?php echo  '<option value="$row["author"]">"$row["author"]"</option>'; ?></p>     <?php }     echo "</select>"; ?>  </body> </html> 

is shows $row["author"] in dropdown.

can solve problem???

thank you.

my database

id  author  book_name language price 1   kishore 1       english  500 2   kumar   2       english  600 3   kishore 3     german   700 

you should use double quotes variable expanding, or exit string , concat normally.

also, change while($stmt->fetch()){?>

echo '<option value="'.$author.'">"'.$author.'"</option>'; 

try using query instead:

"select author, book_name, language bk_tst_fltr group author" 

Comments

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -