View Full Version : PHP To CSV
DC121782
02-16-2010, 01:56 PM
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.
fileserverdirect
02-16-2010, 09:29 PM
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:
<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:
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 :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.