mysql_fetch_array will give me an array of a fetched row. What\'s the best way generate an array from the values of all rows in one column?
$query = mysql_query('SELECT * from yourTable');
function mysql_field_array( $query ) {
$field = mysql_num_fields( $query );
for ( $i = 0; $i < $field; $i++ ) {
$names[] = mysql_field_name( $query, $i );
}
return $names;
}
$fields = mysql_field_array( $query );
$output = implode( ',', $fields ); //outputs the columns names
//echo count( $fields ); //this use if you want count of columns.
$columns = '{\"fields\":\".json_encode($output).\"}';
echo $columns; //for JSON output