更改php数组输出

i have this function

public function select($table, $rows = '*', $join = null, $where = null, $order = null, $limit = null){

        $q = 'SELECT '.$rows.' FROM '.$table;
    if($join != null){
        $q .= ' JOIN '.$join;
    }
    if($where != null){
            $q .= ' WHERE '.$where;
        }
        if($order != null){
                $q .= ' ORDER BY '.$order;
    }
        if($limit != null){
                $q .= ' LIMIT '.$limit;
        }

    if($this->tableExists($table)){

        $query = @mysql_query($q);
        if($query){

            $this->numResults = mysql_num_rows($query);

            for($i = 0; $i < $this->numResults; $i++){
                $r = mysql_fetch_array($query);
                $key = array_keys($r);
                for($x = 0; $x < count($key); $x++){

                    if(!is_int($key[$x])){
                        if(mysql_num_rows($query) > 1){
                            $this->result[$i][$key[$x]] = $r[$key[$x]];
                        }else if(mysql_num_rows($query) < 1){
                            $this->result = null;
                        }else{
                            $this->result[$key[$x]] = $r[$key[$x]];
                        }
                    }
                }
            }
            return true;
        }else{
            array_push($this->result,mysql_error());
            return false; // No rows where returned
        }
    }else{
        return false;
    }
}

If i use this function and my database is empty, my Array looks like this

Array( )

this is fine!

If my database has 1 entries, it looks like this:

Array
(
    [id] => 1
    [a] => 0
    [b] => 0
)

This is not fine, because, if it has more entries than 1 it looks like this:

Array
(
    [0] => Array
        (
            [id] => 1
            [a] => 0
            [b] => 0
        )

    [1] => Array
        (
            [id] => 2
            [a] => 1
            [b] => 1
        )

)

What I want, is that the output with one single entry looks like this:

Array
(
    [0] => Array
        (
            [id] => 1
            [a] => 0
            [b] => 0
        )
)

How do I have to change the function to get this output?

change

if(mysql_num_rows($query) > 1){
    $this->result[$i][$key[$x]] = $r[$key[$x]];
}else if(mysql_num_rows($query) < 1){
    $this->result = null;
}else{
    $this->result[$key[$x]] = $r[$key[$x]];
}

with

if(mysql_num_rows($query) >= 1){
    $this->result[$i][$key[$x]] = $r[$key[$x]];
}else{
    $this->result = null;
}

Your error was in the line :

if(mysql_num_rows($query) > 1){

You have to take into account the first row, so "> 1" become "> 0"

The whole function should look like this :

public function select($table, $rows = '*', $join = null, $where = null, $order = null, $limit = null){

    $q = 'SELECT '.$rows.' FROM '.$table;
if($join != null){
    $q .= ' JOIN '.$join;
}
if($where != null){
        $q .= ' WHERE '.$where;
    }
    if($order != null){
            $q .= ' ORDER BY '.$order;
}
    if($limit != null){
            $q .= ' LIMIT '.$limit;
    }

if($this->tableExists($table)){

    $query = @mysql_query($q);
    if($query){

        $this->numResults = mysql_num_rows($query);

        for($i = 0; $i < $this->numResults; $i++){
            $r = mysql_fetch_array($query);
            $key = array_keys($r);
            for($x = 0; $x < count($key); $x++){

                if(!is_int($key[$x])){
                    if(mysql_num_rows($query) > 0)
                        $this->result[$i][$key[$x]] = $r[$key[$x]];
                    else 
                        $this->result = null;                        
                }
            }
        }
        return true;
    }else{
        array_push($this->result,mysql_error());
        return false; // No rows where returned
    }
}else{
    return false;
}
}