我有一个关于记录选择列表的问题。
这是我的数据库
|Height | Width|
|82 | 450 |
|110 | 450 |
|120 | 450 |
|140 | 600 |
|150 | 700 |
PHP代码
<?php
function width(){
mysql_connect("localhost", "root", "root") or
die("Could not connect: " . mysql_error());
mysql_select_db("partition");
$query = "SELECT width FROM width_height where width='450' limit 1;";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
echo("$row[0]");
mysql_free_result($result);
}
?>
<p>Width (MM):
<select name="width" id="width1">
<option><?php width(); ?></option>
</select><br>
我期待选择列表:
Width: |450|
|600|
|700|
在这里,我想取出450,600,700条记录并在选择列表中显示
是SQL语言问题还是PHP ... ??? 向我提出建议?
答案 0 :(得分:0)
要获取唯一的宽度列表,请将查询更改为
$query = "SELECT DISTINCT width FROM width_height;";
答案 1 :(得分:0)
您也可以尝试:
select width from width_height group by width