User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,979 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,126 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 332 | Replies: 7
Reply
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Can i insert a record without WHILE or FOR loop???

  #1  
May 8th, 2008
Dear all,

I have a table in mysql and i want to insert records into the table without using "FOR" or "WHILE" loop..Can this be done??

Thanks in advance..

Jino.
We only have to do a very few things right in our life, so long as we don't do too many things wrong.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 238
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: Can i insert a record without WHILE or FOR loop???

  #2  
May 8th, 2008
What do you mean by without using for or while loop ? What's the problem in inserting a record directly ? ie., insert into tablename (col1,col2) values ('val1','val2')
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Re: Can i insert a record without WHILE or FOR loop???

  #3  
May 8th, 2008
not that i want to insert More than 100 records into my database with a single query.... I need this for making the things fast..

Is that possible??

Thanks
We only have to do a very few things right in our life, so long as we don't do too many things wrong.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 238
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: Can i insert a record without WHILE or FOR loop???

  #4  
May 8th, 2008
If you know the values, you can do something like this.
  1. INSERT INTO table (col1) VALUES (val1),(val2),(val3)
This will insert 3 records to the table.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Re: Can i insert a record without WHILE or FOR loop???

  #5  
May 8th, 2008
nave it is ok when we enter the records manually and we know the no. of records

Here it is not the case... I have an array having the value of several records that i it got as a result of a query..

I now want to insert these records into an another table without using the while or for loop...
Hope u get me..

Thanks in advance..
Jino.
We only have to do a very few things right in our life, so long as we don't do too many things wrong.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 238
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: Can i insert a record without WHILE or FOR loop???

  #6  
May 8th, 2008
Ah ! Then, *I think* you need a loop to do that.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Re: Can i insert a record without WHILE or FOR loop???

  #7  
May 8th, 2008
I am trying to do that without a loop...

cos that will make things done faster..

Pls get back to me if u get any idea about this..

Once again thx
Jino.
We only have to do a very few things right in our life, so long as we don't do too many things wrong.
Reply With Quote  
Join Date: Jul 2006
Location: Remunj
Posts: 166
Reputation: pritaeas is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 17
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Junior Poster

Re: Can i insert a record without WHILE or FOR loop???

  #8  
May 9th, 2008
If you use the mysqli interface, you can concat all queries into a single string, separated by semi-colons. Then all will be executed after one another. The error-handling will be more difficult though. See here:
http://nl.php.net/manual/en/mysqli.multi-query.php
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 9:34 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC