i have a csv file in folloeing format
book_nam , author , publisher
abcd , zyz , hij
i want this csv file to put in data base in following format
Id_no , book_id , field_nm, value
xx , 1 , book_nam,abcd
xx , 1 , author,zyz
xx , 1 , publisher,hij
actually from csv file book_name will be picked up first , will be matched in another table from where book_id will be picked up and then i have to insert this code into next tabe in above format .
code i have written is this : -
<?php
-
$f_name = array();
-
-
$conn = mysql_connect("localhost","zzzzz","vvvvv");
-
$db = mysql_select_db("mmmmm");
-
$fh = fopen("Book1.csv", "r");
-
$count1 = 0 ;
-
-
while($line = fgetcsv($fh, 1000, ","))
-
{
-
$count1 = $count1+1;
-
count($line);
-
if($count1 == 1)
-
{
-
-
for($i=0;$i<=count($line);$i++)
-
{
-
-
$f_name[i] = $line[$i];
-
-
-
-
}
-
-
}
-
-
-
$pname = $line[0];
-
echo $qry = "select productid from isc_products where prodname = '".$pname."'";
-
$result = mysql_query($qry);
-
while($row = mysql_fetch_array($result))
-
{
-
$pid = $row["productid"];
-
-
}
-
-
for($i=1;$i<=(count($line)-1);$i++)
-
{
-
global $f_name;
-
$k= $i-1;
-
$fld_nm = $f_name[$k];
-
$val = $line[$i];
-
echo $qry1 = "insert into isc_product_customfields values(,'$pid','$fld_nm','$val')";
-
-
}
-
echo "\n";
-
-
-
-
-
}
-
mysql_close();
-
fclose($fh);
-
?>
-
-
till now i am just printing the query .
i am stucing at a point , i am getting query build but without field_nm in it .
pls help
8 1705
Shalini,
If I read the question correctly you want to know how to run the insert command so that it updates the database. -
$lnNewID = mysql_query($qry1, $conn) or die("Error: ". mysql_error());
-
This should sort you out and give you the new ID should you need for anything else.
If I've mis-understood or there's anything else I can help with just pot back.
Cheers
nathj
its giving me ID but will insert data into another table for which i need to generate a query , which i am not getting : - for($i=1;$i<=(count($line)-1);$i++)
-
{
-
global $f_name;
-
print_r($f_name);
-
$k= $i-1;
-
$fld_nm = $f_name[$k];
-
$val = $line[$i];
-
echo $qry1 = "insert into isc_product_customfields values(,'$pid','$fld_nm','$val')";
-
-
}
has to insert data in converted format :
csv file has data like :
Prodname , author , publisher
xyz , hij , opq
but i need to put in a table whic is having feilds like
Record_no(auto gen),Prod_id,field_name,value
101 , I , Prodname , xyz
102 , I , author ,hij
103 , I , publisher ,opq
i think i am clear now .......
After taking ID ,
I'm sorry but I'm not sure I understand the problem. If you could answer a couple of questions for me I may be able to get a clearer picture of what is going on.
1. How many CSV files are?
2. If there are multiple CVS files are they connected in any way?
I think you may want to use loops to process the information, but as I don't fully understand (my bad) then I can't help further. I'll have another think when you have answered my questions.
Cheers
nathj
i havi one csv file as follows :
Book1.csv -
-
-
prod_name , author , publisher
-
abcd , hij , opq
-
-
-
-
and 2 data bases :
prod_master and another is storing custom fields for pro_master called : pro_custom_field . author , publisher are custom field name and abcd , hij are values for custom fields.
which my client will give me in Book1.csv format.
and i have to insert this data in pro_custom_field like this -
-
rec_ID , Pro_ID , custom_fld_nam , value i.e
-
101 , 1 , author , abcd
-
-
just try to understand the realtion ship of csv file and pro_master then you will be cleared.
if not still cleared , leave it i have changed the csv format and have solved it .
Thanks.
@Shalini Bhalla -
$lnNewID = mysql_query($qry1, $conn) or die("Error: ". mysql_error());
-
The 'or die' part of this statement would do what you are after.
As for the CSV format, I do now understand what you are after, so I'm sorry for being a bit slow to catch on. I'm glad you have solved the problem.
Cheers
nathj
but if still you can tell me that why my global array in that CSV problem is not working , i will be glad ....
my global array is not working in that code which i posted earlier second time.....
thankyou
but "die " will stop the execution also ....... i don't want to stop in between ....it should continue till eof
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Fran Tirimo |
last post by:
I am developing a small website using ASP scripts to format data retrieved
from an Access database. It will run on a Windows 2003 server supporting
FrontPage extensions 2002 hosted by the company...
|
by: Fran Tirimo |
last post by:
I am developing a small website using ASP scripts to format data retrieved
from an Access database. It will run on a Windows 2003 server supporting
FrontPage extensions 2002 hosted by the company...
|
by: varlagas |
last post by:
We disabled the antivirus software but the problem persists. Any clues?
Many thanks in advance!
Panagiotis Varlagas
=======================================================================
...
|
by: Andrew Dowding |
last post by:
Hi Everybody,
I have been looking at problems with my Windows Forms C# application
and it's little Jet 4 (Access) database for the last few days. The
Windows Forms app implements a facade and...
|
by: Julie |
last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB)
for a given string.
The files are unindexed and unsorted, and for the purposes of my immediate
requirements, can't...
|
by: Seok Bee |
last post by:
Dear Experts,
I currently trying to use the FileUpload control from asp.net 2.0 to upload
files. The uploading of the file I would like to store it in the Access
Database. Unfortunately, I've no...
|
by: Miro |
last post by:
I will ask the question first then fumble thru trying to explain myself so i
dont waste too much of your time.
Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an
index - i...
|
by: B. Williams |
last post by:
I need some assistance with random access file processing. I have a function
that I would like to change from sequential file processing to random
access. Thanks in advance.
void...
|
by: lxyone |
last post by:
Using a flat file containing table names, fields, values whats the
best way of creating html pages?
I want control over the html pages ie
1. layout
2. what data to show
3. what controls to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |