Jump to content

Search the Community

Showing results for tags 'csv download'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 3 results

  1. The code below worked perfectly on my old hosting service. I've had to move to a new host and I get this error when I try to run the code. This is the code:- <?php // connect to DATABASE! include_once('../user/dbconfig.php'); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $options = [ \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, \PDO::ATTR_EMULATE_PREPARES => false, ]; $dsn = "mysql:host=$host;dbname=$dbname;charset=$charset;port=$port"; try { // create a PDO connection with the configuration data $conn = new PDO($dsn, $user, $dbpassword, $options); } catch (PDOException $e) { // report error message echo $e->getMessage(); } $ans = $_POST['answer']; //Setup the filename that our CSV will have when it is downloaded. if($ans == 'yes'){ $fileName = 'answers-right.csv'; } elseif ($ans == 'no') { $fileName = 'answers-wrong.csv'; } // Create our SQL query. $sql = 'SELECT ID,email,firstname,lastname,message FROM checks WHERE answer = ?'; $stmt = $conn->prepare($sql); $stmt->execute([$ans]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // NB: now using fetchAll because there's going to be more than one record //Get the column names. $columnNames = array(); if(!empty($rows)){ //We only need to loop through the first row of our result //in order to collate the column names. $firstRow = $rows[0]; foreach($firstRow as $colName => $val){ $columnNames[] = $colName; } } //If the file exists and is writeable then delete it if(is_writable($fileName)){ //Delete the file $deleted = unlink($fileName); } //Set the Content-Type and Content-Disposition headers to force the download. header('Content-Type: application/excel'); header('Content-Type: application/excel Content-Disposition: attachment; filename="' . $fileName . '"'); //Open up a file pointer $fp = fopen('php://output', 'w'); //Start off by writing the column names to the file. fputcsv($fp, $columnNames); //Then, loop through the rows and write them to the CSV file. foreach ($rows as $row) { fputcsv($fp, $row); } //Close the file pointer. fclose($fp); ?> Would appreciate some help please?
  2. I am generating a csv dynamically and getting it downloaded from php but after download the csv only contain the data from database not the heading or the column name of the database. example: my table contain "users" as column name and it has 4 rows like "ram" "sam" "hari" "sita". then after download of csv, the csv is showing only ram, sam, hari sita not the column name users. How to do that? because it is difficult to know who the ram sam are,, are they any vegetables or users
  3. Hi! The user upload a csv file to the server. next time he want to upload another csv file. if we have collisoin on the rows, have to ask the user to delete it or insert a new record. then we have to make the changes. Our question is: when we save the file only the changes will be saved in the server, or the whole file will be saved by the php? Thank you
×
×
  • 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.