tmartin314
tmartin314

Reputation: 4171

Changing the array return of php/mysql function

I have this get_all function:

function get_all($query)
{
    $res = mysql_query($query);
    $arr_res = array();
    while($row = mysql_fetch_array($res))
        $arr_res[] = $row;
    mysql_free_result($res);

    return $arr_res;
} 

It returns this array of data, which is what I need, but I don't want the first item of each array "[0]" to be returned with it:

   Array
    (
        [0] => Array
            (
                [0] => gallery-1-1310312288_logo.jpg
                [post_image] => gallery-1-1310312288_logo.jpg
            )

    )

How can I alter the function to drop this extra item?

Upvotes: 0

Views: 62

Answers (1)

Dan Smith
Dan Smith

Reputation: 5685

Change this line:

while($row = mysql_fetch_array($res, MYSQL_ASSOC))

By default mysql_fetch_array will return the numerical array index and the associative one - adding the second parameter will make the function only return the associate index.

Upvotes: 4

Related Questions