Jump to content

rseigel

Members
  • Posts

    88
  • Joined

  • Last visited

Everything posted by rseigel

  1. LOL....I guess I figured it couldn't possibly be that easy. Turns out it was..... Thanks.
  2. One last thing and this code is complete. I'm trying to add a header above the field names in the csv. $result = mysqli_query($con,"SELECT * FROM amazon"); $num_fields = mysqli_num_fields($result); $headers = array(); for ($i = 0; $i < $num_fields; $i++) { $headers[] = mysqli_fetch_field_direct($result, $i)->name; } $fp = fopen('amazon.csv', 'w'); if ($fp && $result) { $list = array ( array('TemplateType=Offer', 'Version=2014.0703') ); foreach ($list as $fields) { fputcsv($fp, $fields); } fputcsv($fp, $headers, "\t"); while ($row = mysqli_fetch_row($result)) { fputcsv($fp, array_values($row), "\t"); } } Problem is I need a Tab separating the fields - not a comma. So: array('TemplateType=Offer', 'Version=2014.0703') needs to be something else. Maybe I'm overcomplicating this? Any ideas? Thanks Ron
  3. PERFECT! Thank you! Here's the updated code. I needed it to be tab delimited so I added that as well. $result = mysqli_query($con,"SELECT * FROM amazon"); $num_fields = mysqli_num_fields($result); $headers = array(); for ($i = 0; $i < $num_fields; $i++) { $headers[] = mysqli_fetch_field_direct($result, $i)->name; } $fp = fopen('amazon.csv', 'w'); if ($fp && $result) { fputcsv($fp, $headers, "\t"); while ($row = mysqli_fetch_row($result)) { fputcsv($fp, array_values($row), "\t"); } }
  4. AHHHHHHHHHH..... False alarm. Doesn't work after all. I'll create a new thread to try to figure out how to make this work.
  5. Just to complete this... Here's the code I used to create the csv file: $result = mysqli_query($con,"SELECT * FROM amazon'"); $num_fields = mysqli_num_fields($result); $headers = array(); for ($i = 0; $i < $num_fields; $i++) { $headers[] = mysqli_fetch_field_direct($result, $i)->name; } $fp = fopen('php://output', 'w'); if ($fp && $result) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="amazon.csv"'); header('Pragma: no-cache'); header('Expires: 0'); fputcsv($fp, $headers); while ($row = mysqli_fetch_row($result)) { fputcsv($fp, array_values($row)); } } No idea if this is the correct way to do it or not but it works. Off to the next adventure.....
  6. Yup...my host won't touch this one. Time for plan B....
  7. I take it back.... There's no FILES option in my hosting. I've emailed my host to see what they can do about this.... Thanks, Ron
  8. Thanks for the tip in #2. Much appreciated. After that change all is exactly as you have stated. It still doesn't create the file.
  9. I'm trying to run the following: mysqli_query($con,"SELECT * FROM amazon INTO OUTFILE 'amazon.csv'"); It's running from a php file in the root directory. Not sure why it won't create the csv file. Any ideas? Thanks, Ron
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.