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_ or pdo 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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -