dongtang4954
2012-10-15 07:32
浏览 22
已采纳

选择DISTINCT parent_id [关闭]

 //select parent_id - display unique value
<?php
//database connection
$con = mysql_connect("xxxx","xxxx","xxxx");
if (!$con) {
  die('Could not connect: ' . mysql_error());
}
mysql_select_db("btreedata", $con);
//select distinct query
$query  = mysql_query("SELECT DISTINCT parent_id FROM btree");
$result = mysql_query($sql); 
//dropdown list
echo "<select name='parent_id'>"; 
while ($row = mysql_fetch_array($result)) { 
    echo "<option value='".$row[0]."'>".$row[0]."</option>"; 
} 
echo "</select>"; 
?>

output show like this:

1000
1000
1004
1004
1003
1001
1005
1001

how can I display only

1000
1001
1003
1004
1005
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dououde4065 2012-10-15 07:36
    已采纳
    SELECT  parent_id FROM btree group by parent_id order by parent_id ASC
    
    点赞 评论

相关推荐 更多相似问题