php - Displaying data from database in a Dropdown Menu -


i have got php code connect database , retreieve data , display it. trying take data , display in dropdown menu, when dropdown menu displays correct number of options correlates data in database(ie. gives 3 options if there 3 values in db). doesn't display text options blank. ideas why not displaying text?

<?php $dbhost= 'host ip'; $dbuser ='my username'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); $sql='select event_id events'; mysql_select_db('db_name'); $retval= mysql_query($sql, $conn);  echo'<select name=dropdown value=', '>dropdown</option>'; while($r= mysql_fetch_array($retval)) { echo "<option value={$r["event_id"]}>{$r["events"]}</option>"; } echo "</select>"; ?> 

http://i.imgur.com/30uq0ok.png

the link menu returns

thanks

you did not select events database. need select all(*) or required columns name in query .

change query:

$sql='select event_id events'; 

to :

$sql='select * events'; 

you need take option value inside quotes.

change line inside loop:

echo "<option value={$r["event_id"]}>{$r["events"]}</option>"; 

to:

echo "<option value=\"{$r['event_id']}\">{$r['events']}</option>"; 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -