Display One Row to Dropdown List?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nitediver
Forum Contributor
Posts: 109
Joined: Tue Feb 24, 2009 9:05 am

Display One Row to Dropdown List?

Post by nitediver »

Code: Select all

 
----------------
id| type  | cost 
----------------
1 | reg   | 500 
2 | exp   | 600   
----------------
 

Code: Select all

 
<? 
include "conf.php"; 
 
echo "<p>Cost <select city=name id=name>";
 
$cost = "SELECT type,cost from destination";
$reqcost = mysql_query($city) or die ("Error!");
 
while($result=mysql_fetch_array($reqcost))
    {
    echo "<option value=$result[type]>$result[type]</option>";
    }
echo "</select>";
 
?>
 
How to display the output only in one option, because that code generating two,
Also, I want to display one row from database inside the option list,

Code: Select all

| reg   | 500
wanger220
Forum Newbie
Posts: 19
Joined: Tue Feb 02, 2010 8:44 pm

Re: Display One Row to Dropdown List?

Post by wanger220 »

Not sure what you are trying to achieve here ... can you be more descriptive?

The while( ) loop will run through the entire database and repeat the code inside the { } ... and since you have two records in your database, it is generating two <option> lines.
Post Reply