Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 26th January 2006, 20:57
Accura Accura is offline
Junior Member
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data upload from CSV file

Hi,

I'm pretty new at this so excuse ignorance.
2 quick questions.

1)I have a script used to upload data from a CSV file to database.

No matter how many rows are populated in the CSV file it only uploads the first 15 rows of data.

Any Ideas?

2)Also can anyone tell me what the line of code from PHP.ini below does

;session.entropy_length = 16
Reply With Quote
Sponsored Links
  #2  
Old 26th January 2006, 21:08
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

Quote:
Originally Posted by Accura
Hi,

I'm pretty new at this so excuse ignorance.
2 quick questions.

1)I have a script used to upload data from a CSV file to database.

No matter how many rows are populated in the CSV file it only uploads the first 15 rows of data.

Any Ideas?
To what database? MySQL? Which program do you use for uploading? phpMyAdmin?
Any error messages during the upload process?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 26th January 2006, 21:30
Accura Accura is offline
Junior Member
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I use a php script to upload the data to a mysql database.

No error messages.

I know the file size is less than the 2mb limit and I know the first 15 rows are uploaded instantly.

Is it possible to limit the number of rows being uploaded into the DB in the settings.
Reply With Quote
  #4  
Old 26th January 2006, 21:43
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

Please post the content of your PHP script here, if it isn't too long...
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #5  
Old 26th January 2006, 23:10
Accura Accura is offline
Junior Member
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It has too many image tags so it the BB script is not allowing me to post all of it.

These are the sections I feel might be relevant.

I should point out I didn't code this myself.(like I said i'm a beginner)
__________________________________________________ _________
include_once("../../connection.php");
while ($data = fgetcsv($handle, 4096, $separator))
{
if (count($data) >= 15 && $data[0] != "" && $data[1] != "" && $data[2] != "" && in_array($data[3], array("B", "L")) && in_array($data[4], array("R", "C")) && is_numeric($data[5]) && $data[5] >= 0 && is_numeric($data[6]) && $data[6] >= 0 && in_array($data[7], array("T", "F")) && is_numeric($data[9]) && $data[9] >= 0 && in_array($data[10], array("P", "S", "T", "C")) && format_date($data[12]) && format_date($data[13]))
{
mysql_query("insert into properties(property_id, property_description, property_location, property_rooms, property_bathrooms, property_other_details, property_price, property_date_posted, property_last_date_available, agent_id, property_postcode, property_letorbuy, property_contract, property_accepted, property_contract_terms, property_of_week, property_available_from, property_furniture, property_type) values('', '" . str_replace("'", "`", $data[0]) . "', '" . str_replace("'", "`", $data[1]) . "', {$data[5]}, {$data[6]}, '" . str_replace("'", "`", $data[8]) . "', {$data[9]}, now(), str_to_date('" . format_date($data[13]) . "', '%Y-%m-%d %T'), {$_SESSION['user_id']}, '" . str_replace("'", "`", $data[2]) . "', '{$data[3]}', '{$data[10]}', 'T', '" . str_replace("'", "`", $data[11]) . "', 'F', str_to_date('" . format_date($data[12]) . "', '%Y-%m-%d %T'), '{$data[7]}', '{$data[4]}')");
$result = mysql_query("select property_id from properties order by property_id desc limit 1");
$property_id = 0;
if ($array = mysql_fetch_assoc($result))
{
$property_id = $array["property_id"];
}
mysql_free_result($result);
for ($i = 14; $i < count($data); $i++)
{
for ($j = 0; $j < $_POST["image_files_no"]; $j++)
{
if ($data[$i] != "" && str_replace("'", "`", $data[$i]) == str_replace("'", "`", $_FILES["image_files"]["name"][$j]))
{
$result = mysql_query("select image_id from property_images where image_name = '" . str_replace("'", "`", $data[$i]) . "'");
if (mysql_fetch_assoc($result))
{
mysql_free_result($result);
continue 2;
______________________________________________
Reply With Quote
  #6  
Old 27th January 2006, 07:35
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

Quote:
Originally Posted by Accura
__________________________________________________ _________
include_once("../../connection.php");
while ($data = fgetcsv($handle, 4096, $separator))
{
if (count($data) >= 15 && $data[0] != "" && $data[1] != "" && $data[2] != "" && in_array($data[3], array("B", "L")) && in_array($data[4], array("R", "C")) && is_numeric($data[5]) && $data[5] >= 0 && is_numeric($data[6]) && $data[6] >= 0 && in_array($data[7], array("T", "F")) && is_numeric($data[9]) && $data[9] >= 0 && in_array($data[10], array("P", "S", "T", "C")) && format_date($data[12]) && format_date($data[13]))
{
mysql_query("insert into properties(property_id, property_description, property_location, property_rooms, property_bathrooms, property_other_details, property_price, property_date_posted, property_last_date_available, agent_id, property_postcode, property_letorbuy, property_contract, property_accepted, property_contract_terms, property_of_week, property_available_from, property_furniture, property_type) values('', '" . str_replace("'", "`", $data[0]) . "', '" . str_replace("'", "`", $data[1]) . "', {$data[5]}, {$data[6]}, '" . str_replace("'", "`", $data[8]) . "', {$data[9]}, now(), str_to_date('" . format_date($data[13]) . "', '%Y-%m-%d %T'), {$_SESSION['user_id']}, '" . str_replace("'", "`", $data[2]) . "', '{$data[3]}', '{$data[10]}', 'T', '" . str_replace("'", "`", $data[11]) . "', 'F', str_to_date('" . format_date($data[12]) . "', '%Y-%m-%d %T'), '{$data[7]}', '{$data[4]}')");
$result = mysql_query("select property_id from properties order by property_id desc limit 1");
$property_id = 0;
if ($array = mysql_fetch_assoc($result))
{
$property_id = $array["property_id"];
}
mysql_free_result($result);
for ($i = 14; $i < count($data); $i++)
{
for ($j = 0; $j < $_POST["image_files_no"]; $j++)
{
if ($data[$i] != "" && str_replace("'", "`", $data[$i]) == str_replace("'", "`", $_FILES["image_files"]["name"][$j]))
{
$result = mysql_query("select image_id from property_images where image_name = '" . str_replace("'", "`", $data[$i]) . "'");
if (mysql_fetch_assoc($result))
{
mysql_free_result($result);
continue 2;
______________________________________________
It seems as if the highlighted code has to do with your problem. Have you read that software's documentation? I think the authors intended it to be like that...
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #7  
Old 27th January 2006, 07:44
Accura Accura is offline
Junior Member
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I paid someone to help me create this section of the script there wasn't suppose to be a limit on the number to rows I could upload.

I would usually have to upload between 50 and 200 rows.

Any ideas on how to fix it?
Reply With Quote
  #8  
Old 27th January 2006, 09:38
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

I strongly recommend to ask this someone. He knows best how the script works and why it works like that.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #9  
Old 27th January 2006, 10:35
Accura Accura is offline
Junior Member
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It was a contract job from last year.

I've had a few problems but I've been able to fix them myself.

I'm new to php so I needed to be sure the solution wasn't an obvious one.
Reply With Quote
  #10  
Old 10th April 2006, 18:28
22hosting 22hosting is offline
Junior Member
 
Join Date: Apr 2006
Posts: 26
Thanks: 0
Thanked 1 Time in 1 Post
 
Default

If you are interested I have created a set of classes in PHP to perform almost the same sort of thing. However it should be noted that he is using individual SQL Inserts whereas instead he should using the MySQL load inline function which doesn't do individual queries per data item. Alternatively instead of loading into a live database they should create a temporary table and then insert directly into that table and do a load inline from one table to another. That would almost certainly be the most efficient clean way of doing it.

My code is less messy and better commented so hopefully it will be easier to learn from that the person who wrote that script.

If you are contact me using private messages on this board.


Update : It's probably worth noting that the "count($data) >= 15" section is counting the number of items in the array $data. Therefore this shouldn't have anything to do with the number of rows it's inserting into the database. What it does do is check that the number of columns is greater than or equal to 15.

What counts I think is " $_POST["image_files_no"] " as this should return the number of times it performs the select query and draws one result from the inserted data. Therefore I suspect that if you change this to a static value i.e. the number of rows in your CSV file it should print out all the results.The image_files_no is passed from the previous page as it's a $_POST value, or it's a static value set in one of the other core php files.
________
LIVE SEX

Last edited by 22hosting; 22nd August 2011 at 13:05.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail System doesnt work! crichton Installation/Configuration 3 17th September 2007 23:49
Debian install error jf1976 Installation/Configuration 25 19th January 2006 22:31
ISP install problems Debian sarge 3.1 lerra Installation/Configuration 1 5th January 2006 16:37
PHP/MySQL/Apache2/ISPConfig configuration issues? senzapaura General 21 25th December 2005 14:01
/stats doesn't work (password not accepted) Hellbound General 6 15th September 2005 15:34


All times are GMT +2. The time now is 12:30.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.