inserting multiple records from a 2D array

Results 1 to 2 of 2

Thread: inserting multiple records from a 2D array

  1. #1
    Join Date
    Dec 1969

    Default inserting multiple records from a 2D array

    I&#039;m developing a virtual shopping cart utilizing a two-dimentional array [Example: my_array(4,20)] and a session variable. I&#039;m trying to figure out a way of "recording" the virtual shopping cart into a database table when "checking out."<BR><BR>For example:<BR><BR>my_array(4,20) contains the following:<BR><BR>id1122<BR>product name 1<BR>20.00<BR>1<BR><BR>id1123<BR>product name 2<BR>21.00<BR>2<BR>...<BR><BR>(upper bound would be "8")<BR><BR>How can I create an efficient loop to INSERT the above information into a table containing the following columns:<BR><BR>product_id<BR>product_name<BR>prod uct_price<BR>product_quan.<BR><BR>Thank you... :-)

  2. #2
    Join Date
    Dec 1969

    Default Huh? What's wrong with a FOR loop?

    What am I missing? Why can&#039;t you just use a FOR loop and insert one at a time???<BR><BR>&#062; (upper bound would be "8")<BR><BR>No, it would *not* be. It would be either 4 or 20, depending on which upper bound you mean. I think you mean that the highest row number *in use* is 8, yes? <BR><BR>So...<BR><BR>For row = 0 To 8<BR>&nbsp; &nbsp; ... insert info from "row" into db ...<BR>Next<BR><BR>*IF* your DB supports it, you *could* concatenate all the INSERT statements into one big string (separated by ; of course) and then Execute the single string. But, honestly, unless you are on a site with thousands and thousands of hits per hour I&#039;d just do the inserts one at a time. Easier to debug. Easier to write.<BR><BR>( that what you were asking by the word "efficient"??? Duhhh...sorry, just tumbled to it!)<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts