0

how do i make the first form entry that gets sent to the csv go under column heading...?

(i.e.)
I have headers that say Name, Age, weight... and the user submits a form with the following saying Bob, 72, 291... then the data gets sent to the csv... I want all of the data to go under those headers but unfortunately it goes on the same line....

How do i fix that so that it'll display its results under the headers!

WILL POST MY CODE IF NEEDED!

3
Contributors
9
Replies
10
Views
4 Years
Discussion Span
Last Post by LastMitch
0

so by using this?:

def csv(file)
  File.open(file) do|f|
    columns = f.readline.chomp.split(',')

    table = []
    until f.eof?
      row = f.readline.chomp.split(',')
      row = columns.zip(row).flatten
      table << Hash[*row]
    end

    return columns, table
  end
end

but how would i do this with php because I want the header to display on top with all entries display right under it?

0

@<MICHAEL>

but how would i do this with php because I want the header to display on top with all entries display right under it?

Post whole code. So we can see what is going on.

It was my error. I think I gave you the wrong link because you are using csv files.

Read this so you can see how it works:

http://code.google.com/p/php-csv-parser/wiki/howToUse

If you want something more php and mysql and csv then read this:

http://www.internoetics.com/2011/05/16/working-with-csv-text-files-php/

I might need to look that at Crystal ball every now and then.

Edited by LastMitch: grammer

0

Here is the snippet that is responsible:

$csvData = $today . "," . $first_name . "," . $email . "," . $comment . "\n";
$fp = fopen("results.csv", "a" );
if($fp){
    fwrite($fp, $csvData);
    fclose($fp);
    }


$count= count(file("results.csv"));                     
0

@<MICHAEL>

Here is the snippet that is responsible:

That snippet wasn't very helpful. The snippet is only reading and opening the file. It has nothing to do with echoing out the second row.

This is the first file:

<?php

  $csv = new File_CSV_DataSource;

  $csv->load('results.csv'); // boolean

  $csv->getHeaders(); // array('today', 'first_name', 'email', 'comment');

  $csv->getColumn('today'); // array('Mon', 'Tues', 'Wed', 'Thurs');

  $csv->row(1); // array('Mon', 'Micheal', 'donot@do.com', 'Pay Attention');

  $csv->connect(); // array( array('today' => Mon, 'first_name' => Micheal, 'email' => donot@do.com, 'comment' => Pay Attention));

?>

This is the second file:

 <?php
 // usage sample
 $csv = new File_CSV_DataSource;

 // tell the object to parse a specific file
 if ($csv->load('results.csv')) {

 // execute the following if given file is usable
 // get the headers found in file
   $array = $csv->getHeaders();

   // get a specific column from csv file
   $csv->getColumn($array[2]);

   // get each record with its related header
   // ONLY if all records length match the number
   // of headers
    if ($csv->isSymmetric()) {
        $array = $csv->connect();
    } else {
        // fetch records that dont match headers length
        $array = $csv->getAsymmetricRows();
    }

    // ignore everything and simply get the data as an array
    $array = $csv->getrawArray();
 }
 ?>

The code I provided above gives you the freedom to put any row you want.

Edited by LastMitch: grammer

0

I am sorry if it wasn't useful, but that's all i had at the moment... I didn't know what was next but my goal is clear though... I am going to examine the snippets you sent me, and i am going to get back to you as soon as possible...

(sorry if i respond too slow... i have school work, and other extra curricular activities to work on at the same time)

0

quick question... how is the second file being called...?
is it because of this?:

 $csv = new File_CSV_DataSource;
0

@<MICHAEL>

how is the second file being called...?

 //any name you want
 $csv = new file; 

Edited by LastMitch: grammer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.