seperate records for each item (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


ianb -> seperate records for each item (6/15/2006 6:10:04)

ok, ive searched and search but nothing.

im busy setting up a shopping cart, but at the end when the person is suppoed to check out and the items ordred are put into the database there is where i have the problem.

The items get submitted to the DB, but not in its own row, the items are all in one row seperated by commas e.g.

ItemQuantity1, Itemquantity2 | item 1, item2

and not like this:

ItemQuantity1 | item1
ItemQuantity2 | item2

here is the code that processes the form:

!--#include file="../_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'>The Database Results component on this page is unable to display database content. The page must have a filename ending in '.asp', and the web must be hosted on a server that supports Active Server Pages.</div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="insert into OrdersConfirmed (UID, quantity, product) values ( '::UID::', '::quantity::', '::product::')"
fp_sDefault="UID=&quantity=&product="
fp_sNoRecords="No records returned."
fp_sDataConn="scart"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=False
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_sColTypes="&"
fp_iDisplayCols=16
fp_fCustomQuery=True
BOTID=2
fp_iRegion=BOTID
%>
<!--#include file="../_fpclass/fpdbrgn1.inc"-->
<p>
<!--webbot bot="PurpleText" PREVIEW="inserts the order details" --></p>
<!--#include file="../_fpclass/fpdbrgn2.inc"-->
</body></html>


here is the form that sends to above:

<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<% ' FP_ASP -- ASP Automatically generated by a Frontpage Component. Do not Edit.
FP_CharSet = "windows-1252"
FP_CodePage = 1252 %>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title></title>
</head>

<body>

<div align="center">
  <center>
  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="95%" id="AutoNumber4">
    <tr>
      <td width="100%"><font face="Verdana" size="2"><b>Order:</b></font><form method="POST" action="processorder.asp">
        <div align="center">
          <center>
          <table width="95%" border="0" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">
            <thead>
              <tr>
                <td><b>Quantity</b></td>
                <td><b>Product</b></td>
                <td><b>Unit Price</b></td>
                <td><b>Line Total</b></td>
              </tr>
            </thead>
            <tbody>
              <!--webbot bot="DatabaseRegionStart" s-columnnames="UID,orderID,productID,ProductPrice,ProductName,quantity" s-columntypes="202,3,2,202,202,2" s-dataconnection="scart" b-tableformat="TRUE" b-menuformat="FALSE" s-menuchoice s-menuvalue b-tableborder="TRUE" b-tableexpand="TRUE" b-tableheader="TRUE" b-listlabels="TRUE" b-listseparator="TRUE" i-listformat="0" b-makeform="FALSE" s-recordsource="itemsOrdered" s-displaycolumns="UID,orderID,productID,ProductPrice,ProductName,quantity" s-criteria="[UID] EQ {UID} +" s-order s-sql="SELECT * FROM itemsOrdered WHERE (UID =  '::UID::')" b-procedure="FALSE" clientside suggestedext="asp" s-defaultfields="UID=" s-norecordsfound="No records returned." i-maxrecords="256" i-groupsize="0" botid="2" u-dblib="../_fpclass/fpdblib.inc" u-dbrgn1="../_fpclass/fpdbrgn1.inc" u-dbrgn2="../_fpclass/fpdbrgn2.inc" tag="TBODY" preview="<tr><td colspan=64 bgcolor="#FFFF00" align="left" width="100%"><font color="#000000">This is the start of a Database Results region.</font></td></tr>" startspan --><!--#include file="../_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'>The Database Results component on this page is unable to display database content. The page must have a filename ending in '.asp', and the web must be hosted on a server that supports Active Server Pages.</div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="SELECT * FROM itemsOrdered WHERE (UID =  '::UID::')"
fp_sDefault="UID="
fp_sNoRecords="<tr><td colspan=6 align=left width=""100%"">No records returned.</td></tr>"
fp_sDataConn="scart"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=True
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_sColTypes="&UID=202&orderID=3&productID=2&ProductPrice=202&ProductName=202&quantity=2&"
fp_iDisplayCols=6
fp_fCustomQuery=False
BOTID=2
fp_iRegion=BOTID
%>
<!--#include file="../_fpclass/fpdbrgn1.inc"-->
<!--webbot bot="DatabaseRegionStart" endspan i-checksum="9132" --><tr>





<%
Response.buffer=True
If Session("mm_UserName") = "" Then Response.redirect "login.asp"
%>
<%
             
             Total1 = 0
     
             
        
                 productprice = (FP_FieldHTML(fp_rs,"productprice"))
                 Quantity = (FP_FieldHTML(fp_rs,"quantity"))
                 ExtPrice = (FP_FieldHTML(fp_rs,"productprice") * (FP_FieldHTML(fp_rs,"quantity")))
                 total = Total + (Quantity * ProductPrice)
                 
 %>





                <td>
                <input type="text" name="quantity" size="20" value="<%=quantity%>"></td>
                <td>
                <input type="text" name="Product" size="20" value="<%=FP_FieldVal(fp_rs,"ProductName")%>"></td>
                <td>
   
                <input type="text" name="ProductPrice" size="20" value="<%=productprice%>"></td>
                <td> <%=extprice%></td>
              </tr>
              <!--webbot bot="DatabaseRegionEnd" b-tableformat="TRUE" b-menuformat="FALSE" u-dbrgn2="../_fpclass/fpdbrgn2.inc" i-groupsize="0" clientside tag="TBODY" preview="<tr><td colspan=64 bgcolor="#FFFF00" align="left" width="100%"><font color="#000000">This is the end of a Database Results region.</font></td></tr>" startspan --><!--#include file="../_fpclass/fpdbrgn2.inc"-->
<!--webbot bot="DatabaseRegionEnd" endspan i-checksum="56926" --></tbody>
          </table>
          
          </center>
        </div>
        <div align="center">
          <center>
          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="95%" id="AutoNumber7" height="16">
            <tr>
              <td width="25%" height="16"></td>
              <td width="25%" height="16"></td>
              <td width="25%" height="16"><font face="Verdana" size="2"><b>Total</b></font></td>
              <td width="25%" height="16"><%=total%></td>
            </tr>
          </table>
          </center>
        </div>
        <p><font face="Verdana" size="2"><b>Deliver To:</b></font></p>
        <div align="center">
          <center>
          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="95%" id="AutoNumber1">
            <tr>
              <td width="100%">
              <!--webbot bot="DatabaseRegionStart" s-columnnames="U_ID,U_PASSWORD,U_FIRST,U_LAST,U_ADDRESS,U_CITY,U_STATE,U_ZIP,U_EMAIL,U_PHONE,U_FAX,Date,ACCESS" s-columntypes="202,202,202,202,202,202,202,202,202,202,202,135,202" s-dataconnection="classifieds" b-tableformat="FALSE" b-menuformat="FALSE" s-menuchoice="U_ID" s-menuvalue="U_ID" b-tableborder="TRUE" b-tableexpand="TRUE" b-tableheader="TRUE" b-listlabels="TRUE" b-listseparator="TRUE" i-listformat="0" b-makeform="FALSE" s-recordsource="USERS" s-displaycolumns="U_ID,U_PASSWORD,U_FIRST,U_LAST,U_ADDRESS,U_CITY,U_STATE,U_ZIP,U_EMAIL,U_PHONE,U_FAX,Date,ACCESS" s-criteria="[U_ID] EQ {UID} +" s-order s-sql="SELECT * FROM USERS WHERE (U_ID =  '::UID::')" b-procedure="FALSE" clientside suggestedext="asp" s-defaultfields="UID=" s-norecordsfound="No records returned." i-maxrecords="256" i-groupsize="0" botid="1" u-dblib="../_fpclass/fpdblib.inc" u-dbrgn1="../_fpclass/fpdbrgn1.inc" u-dbrgn2="../_fpclass/fpdbrgn2.inc" tag="BODY" preview="<table border=0 width="100%"><tr><td bgcolor="#FFFF00" align="left"><font color="#000000">This is the start of a Database Results region.</font></td></tr></table>" b-wastableformat="FALSE" startspan --><!--#include file="../_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'>The Database Results component on this page is unable to display database content. The page must have a filename ending in '.asp', and the web must be hosted on a server that supports Active Server Pages.</div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="SELECT * FROM USERS WHERE (U_ID =  '::UID::')"
fp_sDefault="UID="
fp_sNoRecords="No records returned."
fp_sDataConn="classifieds"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=False
fp_fMenuFormat=False
fp_sMenuChoice="U_ID"
fp_sMenuValue="U_ID"
fp_sColTypes="&U_ID=202&U_PASSWORD=202&U_FIRST=202&U_LAST=202&U_ADDRESS=202&U_CITY=202&U_STATE=202&U_ZIP=202&U_EMAIL=202&U_PHONE=202&U_FAX=202&Date=135&ACCESS=202&"
fp_iDisplayCols=13
fp_fCustomQuery=False
BOTID=1
fp_iRegion=BOTID
%>
<!--#include file="../_fpclass/fpdbrgn1.inc"-->
<!--webbot bot="DatabaseRegionStart" endspan i-checksum="35199" --><p>
              <font face="Verdana" size="2">
              <input type="text" name="First" size="35" value="<%=FP_FieldVal(fp_rs,"U_FIRST")%>">
              <input type="text" name="Last" size="35" value="<%=FP_FieldVal(fp_rs,"U_Last")%>"></font></p>
              <p>
              <font face="Verdana" size="2">
              <input type="text" name="address" size="35" value="<%=FP_FieldVal(fp_rs,"U_address")%>">,
              <input type="text" name="suburb" size="35" value="<%=FP_FieldVal(fp_rs,"U_city")%>"><b><br>
              </b>
              <br>
              <input type="text" name="postalcode" size="35" value="<%=FP_FieldVal(fp_rs,"U_zip")%>"></font></p>
              <p> </p>
              <p><font face="Verdana" size="2">
              <!--webbot bot="DatabaseResultColumn" s-columnnames="U_ID,U_PASSWORD,U_FIRST,U_LAST,U_ADDRESS,U_CITY,U_STATE,U_ZIP,U_EMAIL,U_PHONE,U_FAX,Date,ACCESS" s-column="U_EMAIL" b-tableformat="FALSE" b-hashtml="FALSE" b-makelink="FALSE" clientside b-menuformat preview="<font size="-1">&lt;&lt;</font>U_EMAIL<font size="-1">&gt;&gt;</font>" startspan --><%=FP_FieldVal(fp_rs,"U_EMAIL")%><!--webbot bot="DatabaseResultColumn" endspan i-checksum="11534" --></font></p>
              <p><font face="Verdana" size="2">
              <!--webbot bot="DatabaseResultColumn" s-columnnames="U_ID,U_PASSWORD,U_FIRST,U_LAST,U_ADDRESS,U_CITY,U_STATE,U_ZIP,U_EMAIL,U_PHONE,U_FAX,Date,ACCESS" s-column="U_PHONE" b-tableformat="FALSE" b-hashtml="FALSE" b-makelink="FALSE" clientside b-menuformat preview="<font size="-1">&lt;&lt;</font>U_PHONE<font size="-1">&gt;&gt;</font>" startspan --><%=FP_FieldVal(fp_rs,"U_PHONE")%><!--webbot bot="DatabaseResultColumn" endspan i-checksum="11519" --></font></p>
              <p><font face="Verdana" size="2">
              <!--webbot bot="DatabaseResultColumn" s-columnnames="U_ID,U_PASSWORD,U_FIRST,U_LAST,U_ADDRESS,U_CITY,U_STATE,U_ZIP,U_EMAIL,U_PHONE,U_FAX,Date,ACCESS" s-column="U_FAX" b-tableformat="FALSE" b-hashtml="FALSE" b-makelink="FALSE" clientside b-menuformat preview="<font size="-1">&lt;&lt;</font>U_FAX<font size="-1">&gt;&gt;</font>" startspan --><%=FP_FieldVal(fp_rs,"U_FAX")%><!--webbot bot="DatabaseResultColumn" endspan i-checksum="7373" --></font></p>
              <!--webbot bot="DatabaseRegionEnd" b-tableformat="FALSE" b-menuformat="FALSE" u-dbrgn2="../_fpclass/fpdbrgn2.inc" i-groupsize="0" clientside tag="BODY" preview="<table border=0 width="100%"><tr><td bgcolor="#FFFF00" align="left"><font color="#000000">This is the end of a Database Results region.</font></td></tr></table>" startspan --><!--#include file="../_fpclass/fpdbrgn2.inc"-->
<!--webbot bot="DatabaseRegionEnd" endspan i-checksum="56926" --><p>
              <font face="Verdana" size="2"> </font></td>
            </tr>
          </table>
          </center>
        </div>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Verdana" size="2"><b>Delivery Options:</b></font></p>
        <div align="center">
          <center>
          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="95%" id="AutoNumber5">
            <tr>
              <td width="100%">
              <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber6">
                <tr>
                  <td width="50%"><font face="Verdana">
                  <input type="radio" value="Collect" name="DeliveryOptions"><font size="2">I 
                  Will Collect</font></font></td>
                  <td width="50%"><font face="Verdana">
                  <input type="radio" value="Post" name="DeliveryOptions"><font size="2">Please 
                  send it to me</font></font></td>
                </tr>
                <tr>
                  <td width="50%"> </td>
                  <td width="50%"> </td>
                </tr>
                <tr>
                  <td width="50%"><font face="Verdana" size="2">Collections can 
                  be made from:</font><p><font face="Verdana" size="2">Edenvale 
                  JHB</font></p>
                  <p><font face="Verdana" size="2">Garsfontein PTA</font></td>
                  <td width="50%"><font face="Verdana" size="2">We will contact 
                  you with a quote regarding delivery costs</font></td>
                </tr>
              </table>
              <p> </td>
            </tr>
          </table>
          </center>
        </div>
        <p> </p>
        <p><font face="Verdana">
        <input type="submit" value="Process Order" name="B1"></font></p>
        <input type="hidden" name="UID" value="<%=session("mm_UserName")%>">
      </form>
      <p><font face="Verdana" size="2"><br>
</font></td>
    </tr>
  </table>
  </center>
</div>

</body>

</html>


please help





rdouglass -> RE: seperate records for each item (6/15/2006 9:35:06)

quote:

<input type="text" name="quantity" size="20" value="<%=quantity%>


Your problem is in how you name your fields. By naming all your "quantity" fields all the same name, when the form handler does a request.form("quantity"), all quantities come back in a single field like this "2,4,1" or something close to it.

What you need is to name each quantity field distinctly with a row number, a record ID, or some other value. See, what you want is form fields looking like this:

<input type="text" name="quantity1" size="20" value="<%=quantity%>

and

<input type="text" name="quantity2" size="20" value="<%=quantity%>

so then you are able to differentiate between each line item when you update the DB. How you differentiate them is the key. I try to use the record ID if possible if you already have that when you add the item to the cart.

That help any? I suspect you'll have more. [;)]




rdouglass -> RE: seperate records for each item (6/15/2006 9:37:25)

Oh yeah, did I mention building a shopping cart is no trivial thing? [;)] However, there are a lot of 'em already built for quite reasonable costs. What's your time worth? To me, it's not worth the effort to do my own when there are many good ones out there.

Now if all of them don't suit your needs, then by all means build one. [:)]




ianb -> RE: seperate records for each item (6/15/2006 9:42:09)

Firstly, thank you for your response.

im not quite with you here.

the problem with that is the data is populated from a database, so i can only have one quantity.

but it duplicates depending how many items are ordered.

or am i missing something here?




ianb -> RE: seperate records for each item (6/15/2006 9:44:48)

i have tried many shopping carts, but can seem to find one that suits me. I am almost finished with it except for this one issue.




rdouglass -> RE: seperate records for each item (6/15/2006 10:07:15)

quote:

the problem with that is the data is populated from a database, so i can only have one quantity.


Yes, I do understand that. But you have to remember it is 1 quantity per item and the trick is to identify which item each quantity belongs to. And to do that you have to uniquely name each quantity field or all quantities will be in 1 field and not separated.

Does that make any sense?

EDIT: You'd need to do the same with other tiems as well other than quantites.




ianb -> RE: seperate records for each item (6/15/2006 10:13:30)

but i only have one quantity field

(removed super-huge pic - rdouglass)




rdouglass -> RE: seperate records for each item (6/15/2006 10:15:13)

OK. So they can only order 1 item?




ianb -> RE: seperate records for each item (6/15/2006 10:19:23)

http://pets4u.ihost4u.co.za/scart

can order as many items as they want





rdouglass -> RE: seperate records for each item (6/15/2006 10:24:26)

So they can like order 1 of the first item and 3 of the second?

If so then you need separate quantity fields for each item. This is the key I'm trying to show you. Yes you only have 1 quantity per item but you want to have more than 1 item.

Please remember this is on the web form and *not* in the database.

You need to distinguish each quantity field (as well as each other field relating to each item in the cart) so they don't all 'mash' together.




rdouglass -> RE: seperate records for each item (6/15/2006 11:20:52)

Here is a search I did on this site that has a lot of references to updating multiple records using a single form. Browse thru a few of these and I think some of them may help a lot.

http://www.frontpagewebmaster.com/searchpro.asp?phrase=update+multiple+records&author=&forumid=6&topicreply=both&message=body&timeframe=%3E&timefilter=0&language=single&top=300&criteria=AND&minRank=0&sortMethod=r&submitbutton=+OK+




ianb -> RE: seperate records for each item (6/15/2006 11:43:14)

i think this is what i am looking to do

http://www.frontpagewebmaster.com/m-229249/key-insert%252Cmultiple%252Crecords/tm.htm#229249

i am correct and if so how would i go about implementing it into my code?




rdouglass -> RE: seperate records for each item (6/15/2006 11:50:08)

To start with, can you sucessfully UPDATE 1 item? If so, can you post the code?




ianb -> RE: seperate records for each item (6/15/2006 11:55:13)

yes,

im not updating im inserting

this is the code that inserts:

!--#include file="../_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'>The Database Results component on this page is unable to display database content. The page must have a filename ending in '.asp', and the web must be hosted on a server that supports Active Server Pages.</div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="insert into OrdersConfirmed (UID, quantity, product) values ( '::UID::', '::quantity::', '::product::')"
fp_sDefault="UID=&quantity=&product="
fp_sNoRecords="No records returned."
fp_sDataConn="scart"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=False
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_sColTypes="&"
fp_iDisplayCols=16
fp_fCustomQuery=True
BOTID=2
fp_iRegion=BOTID
%>
<!--#include file="../_fpclass/fpdbrgn1.inc"-->
<p>
<!--webbot bot="PurpleText" PREVIEW="inserts the order details" --></p>
<!--#include file="../_fpclass/fpdbrgn2.inc"-->
</body></html>




rdouglass -> RE: seperate records for each item (6/15/2006 12:26:23)

What you have to do is somehow loop thru each line and grab the item parameters and then run the INSERT.

Did you read any of those examples in the search results I posted? There are at least 3 examples of this in the first dozen or so results. Please read those over closely.

You must, I repeat *must* somehow identify each individual item of each line as being separate and distinct items. Then you'd do something like this each time thru the loop:
<%

FOR i = 0 TO howManyLoopItems
...

myQuery = "insert into OrdersConfirmed (UID, quantity, product) values ( '::UID" & identifyer & "::', '::quantity" & identifyer & "::::', '::product" & identifyer & "::::')"
...

...

<%
fp_sQry= myQuery
fp_sNoRecords="No records returned."
fp_sDataConn="scart"
...

NEXT
%>

Something like that. The point is we need to loop thru each 'line' and insert it individually. The only way I know of to do that (and keep track of what goes with which) is to distinctly identify each field item.




ianb -> RE: seperate records for each item (6/15/2006 12:40:19)

yes, i thought i would need that somewhere.

but how do i identify, not knowing howmany items the person is going to order?

or am i on the wrong track here???

alteratavly, when i get the results in the database (in one record, all together)

is there a way i can display them in the correct format?




rdouglass -> RE: seperate records for each item (6/15/2006 12:54:13)

Let's back up a little here.

I'm not sure how you have your DB organized but normally it's done something like this:

1. A table Customers has customer information with a CustID.
2. A table Orders has order information on it with an OrderID and a CustID field that is related to customer.
3. A table OrderItems has order items in it with quantities and ItemID's (from 4th table) and an OrderID related to orders as well as an OrderItemID.
4. A table Items with items and an ItemID.

So customer logs in and starts an order. An order is created in the Orders table with the customer's CustID.

They pick an item to add to their cart and it is added to the Order Items table with the ItemID and the OrderID relating to the item and the order respecitvely.

Now here is where I see the important part: When you show the cart with the items that have been selected and in the cart, then you can set the fields for each item distinguishable by the OrderItemID when you write the list.

Then you can pull out the OrderItemID from 1 field (a hidden field if you want) and then use that OrderItemID when you UPDATE quantities.

When you do an INSERT, you're just creating a new one however you should be checking to see if the item is already in the cart in which case you should be adding 1 quantity. (See why I'm suggesting gettign one already done?)

The issue is you need to somehow identify each line item in the cart and that each line should be a separate line in a distincrt "order items" table.

Does that make any more sense now?




ianb -> RE: seperate records for each item (6/15/2006 13:07:12)

please have a look at the cart

http://pets4u.ihost4u.co.za/scart

customer logs in

adds product and quantity to temporary table (itemsOrdered)

once he has completed adding all his products
then goes to checkout where it displays what he has put in the temporary table, plus some more options, shipping etc, and postage details.

it then takes all of these details and inserts it into another table (ordersconfirmed)
i do this so that the person cant go back at a later stage, and resubmit a confirmed order.

they can go and start a new one







ianb -> RE: seperate records for each item (6/15/2006 14:31:44)

thank you for all of your help so far.

another alterative to this would be if there is a way to display the comma seperated records in the correct format

this would also work




rdouglass -> RE: seperate records for each item (6/15/2006 15:06:29)

Yes it is an alternative. To separate a comma delimited string:

myArray = split(myString,",")

where myString is the list of items that are separated by commas and myArray will be an array of items addressable like:

myArray(x)

That help?




ianb -> RE: seperate records for each item (6/15/2006 15:08:58)

WOW,

ssllllooowwwlllyyy
[:)]

please give an example so i can understand

thanx




rdouglass -> RE: seperate records for each item (6/15/2006 15:14:26)

If I have this text in a field:

"a,b,d,f"

and want to show each one separately, I can use the split function like so:

<%
myString = "a,b,d,f"
'how you get the text into the variable will vary

myArray = split(myString,",")
'that will 'split' the string into an array

FOR i = 0 TO ubound(myArray)
'allows us to start a loop for each item in the array

Response.write(myArray(i) & "<br>")

NEXT
'Go to next item in the array
%>

Put that on an ASP page and browse to it. CHange the items in myString to whatever you want to split.

Is that what you had in mind?




ianb -> RE: seperate records for each item (6/15/2006 15:20:02)

Nice,

let me try it by getting the data from a DB now

[;)]




ianb -> RE: seperate records for each item (6/15/2006 15:38:27)

ok this is what i have, dont know if ive got it all in the right place??

<!--#include file="_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'></div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="SELECT * FROM OrdersConfirmed"
fp_sDefault=""
fp_sNoRecords="No records returned."
fp_sDataConn="scart"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=False
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_iDisplayCols=3
fp_fCustomQuery=False
BOTID=0
fp_iRegion=BOTID
%>
<!--#include file="_fpclass/fpdbrgn1.inc"-->
<p><b>ProdID:</b> <%mystring = FP_FieldVal(fp_rs,"ProdID")%></p>
<p><b>Quantity:</b> <%mystring1 = FP_FieldVal(fp_rs,"Quantity")%></p>
<p><b>Product:</b> <%mystring2 = FP_FieldVal(fp_rs,"Product")%></p>
<hr>

<%

myArray = split(myString,",")
myArray = split(myString1,",")
myArray = split(myString2,",")


FOR i = 0 TO ubound(myArray) 
'allows us to start a loop for each item in the array 

Response.write(myArray(i) & "<br>") 

NEXT 


%><!--#include file="_fpclass/fpdbrgn2.inc"-->




rdouglass -> RE: seperate records for each item (6/15/2006 16:21:21)

quote:


myArray = split(myString,",")
myArray = split(myString1,",")
myArray = split(myString2,",")


FOR i = 0 TO ubound(myArray)
'allows us to start a loop for each item in the array

Response.write(myArray(i) & "<br>")

NEXT


Close. You'll probably have better luck doing it this way:

myArray = split(myString,",")
myArray1 = split(myString1,",")
myArray2 = split(myString2,",")


FOR i = 0 TO ubound(myArray)
'allows us to start a loop for each item in the array

Response.write(myArray(i) & " - " & myArray1(i) & " - " & myArray2(i) & "<br>")

NEXT

That make sense?




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.15625