开发者

How to make a dropdownlist using mysql query with foreach?

开发者 https://www.devze.com 2023-03-26 02:36 出处:网络
I got a code like this $result1 = mysql_query(\"select distinct Countr开发者_JS百科yfrom mtable UNION SELECT DISTINCT MidEstimate FROM mtable\");

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

精彩评论

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