Jump to content


Photo

inserting multiple records at once


  • Please log in to reply
3 replies to this topic

#1 leeroy1

leeroy1
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 20 January 2005 - 07:17 PM

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

#2 narimanam

narimanam
  • New Members
  • Pip
  • Newbie
  • 1 posts
  • LocationCanada

Posted 13 February 2005 - 08:30 PM

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

View Post


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...
Giving up is for smokers...

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 13 February 2005 - 08:40 PM

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!
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 jesserules

jesserules
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 March 2005 - 11:01 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users