Click to See Complete Forum and Search --> : Fetching results from MySQL with PHP


gregson09
11-30-2006, 11:29 AM
Hello there,

I often run queries which return a result set consisting of a table with just one column. Up until now I have been using fetching results like this...

$row = mysqli_fetch_row( $result );
$id = $row[0];

Is there a better way to be doing this when there is only one column in the result data set?

Thanks very much for your help!
Keith

so_is_this
11-30-2006, 02:05 PM
I don't think so. But, in either case, I prefer to use the following -- because subscripts aren't very intuitive:

$row = mysql_fetch_assoc( $result );
$column_name = $row['column_name'];
The reason you probably have no other choices than to use one of the mysql functions in order to retrieve that single column is because the mysql_query function only returns a resource. A resource is a special variable, holding a reference to an external resource. Since it is external, you have no direct access to it.