Jump to content

Archived

This topic is now archived and is closed to further replies.

leeroy1

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))

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

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--]

Share this post


Link to post
Share on other sites

×

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.