473,396 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to insert 2 arrays into 2 fields in MySQL using Perl

170 100+
hi guys,

i dunno if this post should be in Perl or MySQL

but i'm using Perl DBI to do manupilations now in MySQL

i've got problem trying to input 2 arrays of data into 2 fields at the same time

say for example now i got
Expand|Select|Wrap|Line Numbers
  1.  
  2. @array1 = [ 1 ,2 , 3];
  3. @array2 = [4, 5, 6];
  4.  
and i got say 2 fields User and Time

i tried using this code
Expand|Select|Wrap|Line Numbers
  1. foreach $user(@array1){
  2. $sth -> $dbh ->perpare("INSERT INTO `trial` (User) VALUES ('$user')");
  3. $sth->execute();
  4.  
  5. foreach $time(@array2){
  6. $sth -> $dbh ->perpare("INSERT INTO `trial` (Time) VALUES ('$time')");
  7. $sth->execute();
  8.  
i got the results like:
Expand|Select|Wrap|Line Numbers
  1. User    Time
  2. 1          NULL
  3. 2          NULL
  4. 3          NULL
  5. NULL    4
  6. NULL    5
  7. NULL    6
  8.  
how should i change or input my code so i can get this in the database
Expand|Select|Wrap|Line Numbers
  1. User      Time
  2. 1           4
  3. 2           5
  4. 3           6
  5.  
May 14 '08 #1
3 2717
ronverdonk
4,258 Expert 4TB
This is a coding problem, i.e. a Perl question and I do not think we in the MySQL forum can write the Perl code for that. So this thread is moved to the Perl forum.

moderator
May 14 '08 #2
poolboi
170 100+
alright thanks
once again perl guys
i need your help once again
:)
May 15 '08 #3
Atli
5,058 Expert 4TB
I'm not a Perl person, but MySQL can insert into multiple columns and rows in one query:
For example:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO userTable(UserID, Time) VALUES
  2. (1, 4), (2, 5), (3, 6);
  3.  
Try re-writing your Perl code to take advantage of that.
May 15 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: windandwaves | last post by:
is there a quick way to compare the results from two arrays and note the differences? I have two identical tables in MySql (backup and current table) and I want to work out the differences between...
1
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. For the Build using GCC, the compiler error is...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
2
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to...
3
by: menzies | last post by:
Hi, I"m new to this forum, but I have been trying all day to install DBD::mysql onto my Intel MacBook. I've read lots of forums pages and none have gotten me to a successful 'make test' or a...
2
by: idorjee | last post by:
hello, i'm trying to write a perl cgi script to insert some values that i get from the my html form. i could manage to get the params from the html and process them (that part is not included in...
3
by: Waruna | last post by:
Is there a way to block insert into mysql(5.0) using c api of mysql db.. i.e. say there is a table with 2 columns, one contains char other int then i want to insert 500 records at once,, as i...
15
by: Maarten | last post by:
I've found some answers to my problem on this forum, but not exactly the answer I was looking for. Sorry if I've missed something. This is my situation: I am trying to make an insertion into an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
Oralloy
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,...
0
agi2029
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.