[英]How to combine two distinct mySQL queries?
I have tried to distinct make AND model like make, model
我试图区分make和model之类的
make, model
$result=mysql_query("SELECT distinct make, model FROM used order by make asc");
and afterwards 然后
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['make']?>><?=$row['make']?></option>
<? } ?>
and 和
<? while($row=mysql_fetch_array($make)) { ?>
<option value=<?=$row['model']?>><?=$row['model']?></option>
<? } ?>
but I get only the model to be displayed, and not correct. 但是我只得到要显示的模型,而不是正确的。
Now I am using 现在我正在使用
$make=mysql_query("SELECT distinct make FROM used order by make asc");
$model=mysql_query("SELECT distinct model FROM used order by model asc");
Is there a better way? 有没有更好的办法?
I suspect you are misunderstanding what is happening here: 我怀疑您误解了这里发生的事情:
while($row=mysql_fetch_array($result))
if you: var_dump($row) then you will see it has both columns in it. 如果您:var_dump($ row),那么您将看到它具有两列。 ie $row['make'] and $row['model'] with the values that you expect.
即$ row ['make']和$ row ['model']具有您期望的值。
You need to process both columns at once. 您需要一次处理两个列。
I have no idea what this: 我不知道这是什么:
<? while($row=mysql_fetch_array($make)) { ?>
<option value=<?=$row['model']?>><?=$row['model']?></option>
<? } ?>
is doing but it cannot be helpful. 正在这样做,但无济于事。 It it safe to delete it.
删除它很安全。
I will not create tested code as the 'mysql_*' functions are depreciated in PHP. 我不会创建经过测试的代码,因为PHP中'mysql_ *'函数已弃用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.