0

zend-db に問題があります。使用するfetchall()と、行が重複して返されます。次に例を示します。

{
    "title"         : "Florianópolis",
    "neighborhoods" : [ {
                            "0"      : "6",
                            "1"      : "Abraão",
                            "name"   : "Abraão",
                            "number" : "6"
                        },
                        {
                            "0"      : "9",
                            "1"      : "Açores",
                            "name"   : "Açores",
                            "number" : "9"
                        },
                        {
                            "0"      : "5",
                            "1"      : "Agronômica",
                            "name"   : "Agronômica",
                            "number" : "5"
                        },

ご覧のとおり、名前と番号を 2 回受け取っています。情報を取得するメソッドは次のとおりです。

public function getNeighborhoodsByCity( $city )
{
    try
    {
        $this -> sql = new Sql( $this -> adapter );
        $select = $this -> sql -> select();
        $select -> from( $this -> table );
        $select -> columns( array( 'number',
                                   'name' ) );
        $select -> where( "city = '{$city}'" );
        $select -> order( "name" );
        $statement = $this -> sql -> prepareStatementForSqlObject( $select );
        $result = $statement -> execute() -> getResource() -> fetchall();
    }
    catch ( \Exception $e )
    {
        throw new \Exception ( 'ERROR : ' . $e -> getMessage() );
    }

    return $result;
}

0andを生成しているものを知りたいです1。ところで、私は Zf3 を学習しているので、このコードを改善するためのヒントは大歓迎です! 前もって感謝します!

4

1 に答える 1