Jump to content

inserting multiple records at once


Recommended Posts

I'm trying to create something like the sql below to automatically insert several records into a table. Then once it's done I need the page to automatically forward to another php page. Is this possible? I'm also trying to design the page so that the user can enter a starting number such as 5 and then col35 in tbl95 will sequentially add numbers for each record added. I'm not sure where to begin for all this though. Can dreamweaver do it?

 

INSERT INTO tbl95 ( col13, col2, col27, col28, col30, col31, col32, col33, col34 )

SELECT view1.col23, view1.col2, view1.physician, view1.totaltopay, view1.col4, view1.col5, view1.col6, view1.col7, view1.col8

FROM view1

WHERE (((view1.col23)=recordid66))

Link to comment
Share on other sites

  • 4 weeks later...
I'm trying to create something like the sql below to automatically insert several records into a table.  Then once it's done I need the page to automatically forward to another php page.  Is this possible?  I'm also trying to design the page so that the user can enter a starting number such as 5 and then col35 in tbl95 will sequentially add numbers for each record added.  I'm not sure where to begin for all this though.  Can dreamweaver do it?

 

INSERT INTO tbl95 ( col13, col2, col27, col28, col30, col31, col32, col33, col34 )

SELECT view1.col23, view1.col2, view1.physician, view1.totaltopay, view1.col4, view1.col5, view1.col6, view1.col7, view1.col8

FROM view1

WHERE (((view1.col23)=recordid66))

195542[/snapback]

 

You can easily to hand code all of it. First you need to create a "while" loop and insert one record at a time to your table. When the loop has finished its insert use a redirect method for going to another page:

 

header ("Location: your page URL"); // Redirect browser to other page

exit; // Closes further script execution

 

This function works when you have not sent any php or html command to output any thing in the browser. Care is to be taken not to send any other things to the browser after the header redirection using location command.

 

As for getting user number, you can simply store it in a variable and build your query arround it and then use a FOR loop with ++ to add sequentially to the record number.

 

I geuss you are wondering if dreamweaver can handle all this in its WYSIWYG environement. As your request is very particular I doubt if there is a pre-written peice of code that is desinged for your purpose.

 

hope this helps...

Link to comment
Share on other sites

narimanam has given you a very good suggestion to get started... i would recommend another specific, though... you can link several insert statements together and run them all with only one query to the database quite easily... let's say i want to insert 10 rows into my db, and i just want to insert values of 1001-1010 in a column named "number"... follow along and see if this will help you some:

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]

[span style=\"color:#0000BB\"]<?php

$number [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]1000[/span][span style=\"color:#007700\"];

[/span][span style=\"color:#0000BB\"]$query [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"\"[/span][span style=\"color:#007700\"];

for ([/span][span style=\"color:#0000BB\"]$i [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]0[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$i [/span][span style=\"color:#007700\"]< [/span][span style=\"color:#0000BB\"]10[/span][span style=\"color:#007700\"]; [/span][span style=\"color:#0000BB\"]$i[/span][span style=\"color:#007700\"]++) {

    [/span][span style=\"color:#0000BB\"]$query [/span][span style=\"color:#007700\"].= [/span][span style=\"color:#DD0000\"]\"INSERT INTO table (number) VALUES (\'$number\'); \"[/span][span style=\"color:#007700\"];

}

 

if ([/span][span style=\"color:#0000BB\"]mysql_query[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$query[/span][span style=\"color:#007700\"])) {

    echo [/span][span style=\"color:#DD0000\"]\"Records successfully inserted.\"[/span][span style=\"color:#007700\"];

} else {

    echo [/span][span style=\"color:#DD0000\"]\"Error inserting data.\"[/span][span style=\"color:#007700\"];

}

[/span][span style=\"color:#0000BB\"]?>[/span]

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

 

Hope this helps!

Link to comment
Share on other sites

  • 4 weeks later...

to place header() anywhere, start the whole page with the following:

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]

[span style=\"color:#0000BB\"]<?php

ob_start[/span][span style=\"color:#007700\"]();

[/span][span style=\"color:#0000BB\"]?>

[/span]

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

and end it with this:

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]

[span style=\"color:#0000BB\"]<?php

ob_end_flush[/span][span style=\"color:#007700\"]();

[/span][span style=\"color:#0000BB\"]?>

[/span]

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.