Results 1 to 2 of 2

Thread: PHP To CSV

  1. #1
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP To CSV

    I am trying to create a CSV file using PHP & MYSQL. I need to make a cell have drop down options. Column 1 has a title of Keywords and Column 2 will have a title of Status. I am able to get a CSV file that will list the results, however I need Column 2 to beable to have a select dropdown to make changes so I can then upload the CSV file into my database with the changes.

    Example.

    Column 1 : Column 2
    new york - Approved
    philadlelphia - Approved
    chicago - Declined
    L.A - Pending

    Column 2 will need to have dropdown option with options. I have searched endlessly across the net for a solution and can't find one. Perhaps this just isn't possible.

  2. #2
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Assuming you already have an HTML form for this, if not, you'll want to ask in the respective form; but a select menu would have a very basic format of this:
    HTML Code:
    <select>
    <option>
    number1
    </option>
    <option>
    number2
    </option>
    <option>
    number3
    </option>
    </select>
    You don't really need to download the csv file and then upload it to a MySQL database. Php has it's own functions for data exporting into a MySQL database:
    PHP Code:
    mysql_connect("$host""$username""$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    $name=$_POST['name'];
    $lastname=$_POST['lastname'];
    $email=$_POST['email'];
    //etc...etc...

    $sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";
    $result=mysql_query($sql);
    if(
    $result){
    echo 
    "Successful!";
    }
    else {
    echo 
    "Error";

    This was an automated approach that will save you tons of time. However if you STILL want a CSV file, PHP has a function for that: http://www.php.net/manual/en/function.fputcsv.php
    I don't know much about that function, but I'm sure you'll be enlightened if you check that page out. Also if you want more explanation about that MySql example, just ask
    Last edited by fileserverdirect; 02-16-2010 at 09:37 PM.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •