开发者

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

开发者 https://www.devze.com 2023-03-07 17:40 出处:网络
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'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

精彩评论

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

关注公众号