|
Posted by frizzle on 04/26/06 16:45
Chuck Anderson wrote:
> David Haynes wrote:
>
> >Gerard Matthew wrote:
> >
> >
> >>Frizzle,
> >>
> >>Did the mysql_fetch_array( $get_res, 1 ) change fix the problem?
> >>
> >>
> >>
> >
> >This would probably be clearer as:
> >mysql_fetch_array($get_res, MYSQL_ASSOC);
> >
> >-david-
> >(I hate magic numbers in code ;-) )
> >
> >
> >
> Or use mysql_fetch_assoc instead of mysql_fetch_array.
>
>
> --
> *****************************
> Chuck Anderson · Boulder, CO
> http://www.CycleTourist.com
> Integrity is obvious.
> The lack of it is common.
> *****************************
Thanks guys!
I have it working now. (AFAIK perfectly!)
My function is below.
Thanks again guys!
++++ code ++++
function doQuery( $query, $res_key = NULL ){
$get_res = @mysql_query( $query ) or die(mysql_error());
if( $res = mysql_fetch_assoc( $get_res ) )
{
do{
if( $res_key !== NULL ){
$result[ $res[ $res_key ] ] = $res;
}else{
$result[] = $res;
};
}while( $res = mysql_fetch_assoc( $get_res ) );
}
else
{
$result = false;
};
return $result;
};
++++ / code ++++
you could call it as following:
$my_new_array = doQuery( $query, 'id' ); // will return id (from the
query) as array index
$some_other_name = doQuery( $query ); // will return array with default
index.
Thanks a bunch guys.
(It looks so simple now ...)
Frizzle.
[Back to original message]
|