Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SQL Distinct未删除重复的元素。为什么?_Php_Sql_Wordpress_Distinct - Fatal编程技术网

Php SQL Distinct未删除重复的元素。为什么?

Php SQL Distinct未删除重复的元素。为什么?,php,sql,wordpress,distinct,Php,Sql,Wordpress,Distinct,我正在使用以下查询: $cities = $wpdb->get_results( "select distinct ID , post_title from $wpdb->posts where post_type = 'place' and post_parent = $state_id order by post_title ", ARRAY_A ); 但重复的元素不会被删除。为什么? 以下是全部用法: <label for="veneue_finder_city_sel

我正在使用以下查询:

$cities = $wpdb->get_results( "select distinct ID , post_title from $wpdb->posts where post_type = 'place' and post_parent = $state_id order by post_title ", ARRAY_A );
但重复的元素不会被删除。为什么? 以下是全部用法:

<label for="veneue_finder_city_select">Cityyyyyyyyyyyyyyyyyyyy</label>
                            <select id="veneue_finder_city_select" name="city_id">
                                <option value="">Any</option>
                                <?php
                                if( !empty($state_id) ) {

                                    $states = array();
                                    $cities = $wpdb->get_results( "select distinct ID , post_title from $wpdb->posts where post_type = 'place' and post_parent = $state_id order by post_title ", ARRAY_A );

                                    foreach( $cities as $city ):
                                    ?>

                                        <option value="<?php echo $city['ID']; ?>" <?php selected($city['ID'], $city_id) ?>><?php echo $city['post_title']; ?></option>
                                    <?php endforeach;
                                }?>
                            </select>
cityyyyyyyyyyyyyyyyyy
任何
>

你能举例说明你的结果吗?哪个部分重复?因为ID;)每个帖子都有不同的ID-我说的对吗?编辑你的问题,提供样本数据和期望的结果。你可能只是不明白select distinct是做什么的。我复制了一些城镇,比如:柏林等。@RumenPanchev:有不同的
ID
s?