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!

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?

Member Avatar for diafol

That's funny. ANyway, show your code. Crystal ball gazing otherwise.

Member Avatar for LastMitch

@<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.

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"));                     
Member Avatar for LastMitch

@<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.

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)

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

 $csv = new File_CSV_DataSource;
Member Avatar for LastMitch

@<MICHAEL>

how is the second file being called...?

 //any name you want
 $csv = new file; 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.