开发者

PHP/MySQL dropdown list with multiple columns, trouble with syntax

I'm trying to get a drop down list to display multiple columns from a table, and for the selected row's primary id to be stored in the variable name.

I get a list of rows if I drop the CONCAT function and SELECT a single column, but I can't figure out how to select more than one. What am I doing wrong?

<li>
    <?php 
    $sql="SELECT CONCAT(county,开发者_JS百科 ' ',municipality, ' ',park), id FROM mtmg.locality";
    $result=mysql_query($sql, $connection);

    echo '<label for="county_municipality_park">County, Municipality, Park</label>';
    echo '<select  id="county_municipality_park" name="county_municipality_park">';

    while ($row = mysql_fetch_assoc($result)) {echo '<option value="'.$row['county,municipality,park'].'">'.$row['county,municipality,park'].'</option>';}
    echo mysql_error();

    echo '</select>';
    ?>
</li>


You need to give your CONCAT() function an alias, something like

SELECT CONCAT(county, ' ',municipality, ' ',park) as county_municipality_park, id FROM ...

and then reference it as such in the $row array, i.e. $row['county_municipality_park'].


try this

$sql="SELECT CONCAT(county, ' ',municipality, ' ',park) as location , id FROM mtmg.locality";

and then use $row['location']

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜