423,485 Members | 1,664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,485 IT Pros & Developers. It's quick & easy.

mysql database fields into html list/menu

P: n/a
mysql database "myshop" table "einheit"
"id" field int(255) auto_increment
"name" field varchar(255)

===============
= id = name =
===============
= 1 = Stück =
= 2 = Packung=
= 3 = kg =
= 4 = Box =
===============
I would like to insert these fields into PHP side list/menu , I
already some tried however did not create

my php code

<?
$dbhost = "localhost";
$dbname = "myshop";
$dbuser = "franky";
$dbpass = "pass";

mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);

$sql="select * from einheit";
$result=mysql_query($sql);
$zeile = mysql_fetch_array($result);
echo "$zeile[id] , $zeile[name]";

?>
<select name="select">
<option value="$zeile[id]" selected>$zeile[name]</option>
</select>


ask for assistance Thanks!
Jul 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
fr***@fuka.at (Franz Josef Fuka) wrote:
I would like to insert these fields into PHP side list/menu , I
already some tried however did not create

<?
$dbhost = "localhost";
$dbname = "myshop";
$dbuser = "franky";
$dbpass = "pass";

mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);


You'd have to loop through the result set:

$sql="select * from einheit";
$result=mysql_query($sql);
echo "<select name=\"select\">\n";
while($zeile = mysql_fetch_array($result)){
?>
<option value="<?php echo $zeile['id']; ?>"><?php echo $zeile['name'];
?></option>
<?php
}
?>
</select>

HTH;
JOn
Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.