0

I have a table cene_pretplatne_stanarske which has two columns 'lice' and 'cene'. The first column 'lice' should populate a select, dropdown menu, and the other column, 'cene', should populate a input box, based on the selection of the dropdown menu. I tried this:

<?php

mysql_connect('localhost', 'xxxxx', 'xxxxxxx');
mysql_select_db('xxxxxxx');
mysql_set_charset('utf8');
$sql = "SELECT * FROM cene_pretplatne_stanarske";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$cena = $row ["cena"];
$sql = "SELECT lice FROM cene_pretplatne_stanarske WHERE lice LIKE 'C0%'";
$result = mysql_query($sql);

echo "<select name='lice' onchange='document.getElementById(\'form1\').submit();'>";
while ($row = mysql_fetch_array($result)) 
{
echo "<option value='" . $row['lice'] . "'>" . $row['lice'] . "</option>";
}
echo "</select>";
echo "<input type='text' value='$cena' />";
?>

but it returns empty select box, and the input box with the value of the first row of 'cene' column. Please help.

4

1 回答 1

0

检查返回了多少(如果有)结果:

$i=0;

while ($row = mysql_fetch_assoc($result)) {
    echo "<option value='" . $row['lice'] . "'>" . $row['lice'] . "</option>";
    $i++;
}

echo $i结束后</select>

于 2012-07-05T13:54:27.733 回答