Click to See Complete Forum and Search --> : importing text file into the database!


elbes
07-05-2007, 02:22 AM
hi
i have a text file in the foloowing format:

Abdeljawad Mahmoud H,20070501,72838,919600,
Ali Muhammad Abdelra,20070502,191939,10318676,
Jihad Taha Muhammad ,20070530,160154,10337377,
Zeiad Obeid Abdelwah,20070526,71527,10317148,
Walid Abdelqader Muh,20070515,71325,1017811,
Smer Muhammad Ali Ha,20070526,161435,10318001,
Shadi Abdullah Yassi,20070519,161517,10322208,

in the first and second rows for example the number 72838 is for ckeck in time and the number 191939 is for check out time.

how can i import this file into my database so i will have columns

name,date,check in time,check out time ,ID

can this be done?

temp.user123
07-05-2007, 08:36 AM
That is a CSV file. You can use the PHP fgetcsv() function to read and automatically parse such a file into columns which you, then, easily INSERT into a database table.

chrisranjana
07-05-2007, 11:01 AM
If is it Mysql then you can use phpmyadmin to import CSV files.
Then you can programatically determine the logic for separating check in and check out times

elbes
07-05-2007, 01:35 PM
thnx
but can u please show me how to do it using php page?
i dont want to use phpmyadmin,coz i need the user to import this file and put it into the database to do the calculations.

temp.user123
07-05-2007, 02:10 PM
Upload the CSV file to your site (can use FTP), then check these links:

$fp = fopen (http://us2.php.net/fopen)($file, 'r');
while ((boolean)$data = fgetcsv (http://us2.php.net/fgetcsv)($fp, 512))
{
# process $data array here as needed
}
fclose (http://us2.php.net/fclose)($fp);

elbes
07-05-2007, 02:14 PM
am sorry but can u give a workin full code,coz i didnt get the idea?

temp.user123
07-05-2007, 03:48 PM
Sorry, I'm not going to do *all* the work for you. Post some code to show you're making an effort -- and I'll help you with it.

hastx
07-05-2007, 09:56 PM
As pointed out earlier, you can use phpmyadmin, or you can download any number of prebuilt csv-to-mysql import scripts.

there are free scripts you can download, since there is nothing particularly difficult or unique about what you need. This was my first hit on google: http://www.codewalkers.com/c/a/Database-Code/PHP-CSV-Importer-20/

elbes
07-06-2007, 03:15 AM
its not a matter of importing only,i ned to import the csv file and preview the result in this format
name ID Date Check_in_time Check_out_time