开发者

How to make a dropdownlist using mysql query with foreach?

I got a code like this

$result1 = mysql_query("select distinct Countr开发者_JS百科y  from mtable UNION SELECT DISTINCT MidEstimate FROM mtable");
$row = mysql_fetch_assoc( $result1 );

    echo "<select>";
    foreach($row as $vals)
    {
        echo "<option name='$vals'>$vals</option>";
    }
    echo "</select>";

The dropdownlist list is showing only one value ? I want the values from both columns in this list please help me to sort this


$result1 = mysql_query("select distinct Country  from mtable UNION SELECT DISTINCT MidEstimate FROM mtable");  

echo "<select>";  
while($row = mysql_fetch_array($result1)){
    echo "<option name=\"$row[0]\">$row[0]</option>";
}
echo "</select>"; 


$result1 = mysql_query("select distinct Country  from mtable UNION SELECT DISTINCT MidEstimate FROM mtable");

echo "<select>";
while($row = mysql_fetch_assoc( $result1 ))
{
    echo "<option name=\"$vals['Country']\">$vals['Country']</option>";
}
echo "</select>";

Because you are fecthing your result only once and mysql_fetch_assoc( $result1 ) gets only one row while you want all the rows

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜