php - fetch data from database and display in dropdownlist -
i trying fetch data database , display in dropdownlist cant result try other post here cant understand
anyone can me this project
<?php $connection =mysql_connect('localhost', 'root', '','mjj_app'); $sql="select food menu"; $lists=mysql_query($sql); echo"<select name='fname' id='myselect' value='foodname'>" while($food = mysql_fetch_array($lists)) { echo '<option value='.$food['food'].'>'.$food['food'].'</option>'; } echo '</select>'; ?>
if using mysql_
database extension need select database using mysql_select_db()
you need check each call the mysql_
extension has not returned errors.
<?php $connection =mysql_connect('localhost', 'root', '','mjj_app'); if ( ! $connection ) { echo 'could not connect: ' . mysql_error(); exit; } if ( ! mysql_select_db('database_name') ) { echo 'cant select database : ' . mysql_error(); exit; } $sql="select food menu"; $lists=mysql_query($sql); if ( ! $lists ) { echo 'query failed: ' . mysql_error(); exit; } echo"<select name='fname' id='myselect' value='foodname'>" while($food = mysql_fetch_array($lists)) { echo '<option value='.$food['food'].'>'.$food['food'].'</option>'; } echo '</select>'; ?>
as still learning, spend time learning
mysqli_
orpdo
database extension.mysql_
extension has been deprecated years , totally disapprear in php7, out sometime soon, make code obsolete. see this post read , decide suits you.
Comments
Post a Comment