Bruce Gust
asked on
I need to tweak this code that creats a csv file - Part I
This code works like a champ:
The challenge, however, is that my user wants the headers named "lat" and "long" as opposed to "geo_coords_lat" and "geo_coords_lon." How can I dictate the way the headers appear without changing their name in the database?
$michelle="select actor_id, actor_display_name, posted_time, geo_coords_lat, geo_coords_lon, location_name from twitter_csv_test where geo_coords_lat BETWEEN '$lat_1' AND '$lat_2' and geo_coords_lon BETWEEN '$lon_2' and '$lon_1'";
$michelle_query=mysqli_query($cxn, $michelle);
if(!$michelle_query)
{
$rats=mysqli_errno($cxn).': '.mysqli_error($cxn);
die($rats);
}
$michelle_columns=mysqli_field_count($cxn);
//gets the field names from your table and sets them up as the first row in your csv file
$heading=mysqli_fetch_fields($michelle_query);
foreach ($heading as $val)
{
$output .='"'.$val->name .'",';
}
$output .="\n";
while($michelle_row=mysqli_fetch_array($michelle_query))
{
for($i=0; $i<$michelle_columns; $i++)
{
$output .='"'.$michelle_row["$i"].'",';
}
$output .="\n";
}
$filename="twitter.csv";
header('Content-type:application/csv');
header('Content-Disposition: attachment; filename='.$filename);
echo $output;
The challenge, however, is that my user wants the headers named "lat" and "long" as opposed to "geo_coords_lat" and "geo_coords_lon." How can I dictate the way the headers appear without changing their name in the database?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.