您的位置:程序门 -> web 开发 -> asp



关于一个数组中删除一组数据的问题,十分紧急!!!!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


关于一个数组中删除一组数据的问题,十分紧急!!!!
发表于:2007-03-17 17:07:44 楼主
此数组保存的是一个购物车中的数据  当商品超过2个 我在删除任何一个商品时总是删除的是最后一组商品数据 定义的函数为
function   remove(pic)
if   isarray(session( "arr "))   then
  arr=session( "arr ")
  ub=ubound(arr,1)
   if   ub=0   then
session( "arr ")= " "
   else
flag=false   '标记是否已经删除对应的商品信息
redim   arr_temp(ub-1,14)     '定义临时存储购物车信息的数组
for   i=0   to   ub-1
      if   arr(i,0) <> pic   then
for   j=0   to   14
if   flag   then     '当删除一条商品信息后
      arr_temp(i-1,j)=arr(i,j)
else
arr_temp(i,j)=arr(i,j)
end   if
next
else
flag=true
end   if
next
end   if
end   if
session( "arr ")=arr_temp
end   function
这段函数不知道有问题没?希望大家能帮我看一下  pic这个参数代表的是商品唯一标市号,是删除某个商品的的依据.
发表于:2007-03-17 17:34:111楼 得分:0
有人可以帮帮忙么^^这个问题困惑了我好几天了  希望能有人帮一下
发表于:2007-03-17 18:55:192楼 得分:0
真的没人会还是不屑于告诉一个新手啊^^^^都说这里是高手云集,为什么这么个问题没人解决呢     郁闷!!!
发表于:2007-03-17 19:31:503楼 得分:0
看起来太累了.
是这我以前写的购物车用到的自定义函数.

直接套用吧.

public   sub   createcart()
if   isarray(session( "cart "))   =   false   then
dim   arycart()
redim   arycart(5,0)
session( "cart ")   =   arycart
end   if
end   sub

function   checkcart()
if   isarray(session( "cart "))   then
checkcart   =   true
else
checkcart   =   false
end   if
end   function

function   checkitem(id)
dim   arycart,findflag,i
if   checkcart   =   true   then
arycart   =   session( "cart ")
findflag=false
for   i   =   lbound(arycart,2)   to   ubound(arycart,2)
if   clng(arycart(0,i))   =   id   then
findflag=true
exit   for
end   if
next
checkitem   =   findflag
end   if
end   function

public   sub   removeitem(id)
if   not   checkitem(id)   then
exit   sub
end   if
dim   i,intpos,arycart,newsize
arycart   =   session( "cart ")
for   i   =   lbound(arycart,2)   to   ubound(arycart,2)
if   cint(arycart(0,i))   =   id   then
intpos   =   i
exit   for
end   if
next
for   i   =   intpos   to   ubound(arycart,2)-1
if   not   arycart(0,i)   =   " "   then
arycart(0,i)   =   arycart(0,i+1)
arycart(1,i)   =   arycart(1,i+1)
arycart(2,i)   =   arycart(2,i+1)
arycart(3,i)   =   arycart(3,i+1)
arycart(4,i)   =   arycart(4,i+1)
arycart(5,i)   =   arycart(5,i+1)
end   if
next
newsize=ubound(arycart,2)-1
redim   preserve   arycart(5,newsize)
session( "cart ")   =   arycart
end   sub

public   sub   updateitem(id,num)
dim   aryupdatecart,i
aryupdatecart   =   session( "cart ")
for   i   =   lbound(aryupdatecart,2)   to   ubound(aryupdatecart,2)
if   cint(aryupdatecart(0,i))   =   id   then
aryupdatecart(5,i)   =   num
session( "cart ")   =   aryupdatecart
exit   for
end   if
next
end   sub

public   sub   additem(id,num)
dim   btncartstatus,aryaddcart,newsize,i
btncartstatus   =   checkcart
if   btncartstatus   =   false   then
createcart
set   rs=fs.EXECute( "select   productname,picture,shi_price,hao_price   from   fs_product   where   id= "&id)
aryaddcart   =   session( "cart ")
aryaddcart   (0,0)   =   id
aryaddcart   (1,0)   =   rs( "productname ")
aryaddcart   (2,0)   =   rs( "picture ")
aryaddcart   (3,0)   =   rs( "shi_price ")
aryaddcart   (4,0)   =   rs( "hao_price ")
aryaddcart   (5,0)   =   num
session   ( "cart ")   =   aryaddcart
set   rs=nothing
exit   sub
elseif   btncartstatus   =   true   then
if   checkitem(id)   =   true   then
aryaddcart   =   session( "cart ")
for   i   =   lbound(aryaddcart,2)   to   ubound(aryaddcart,2)
if   cint(aryaddcart(0,i))   =   id   then
aryaddcart(5,i)   =   aryaddcart(5,i)+num
session( "cart ")   =   aryaddcart
exit   for
end   if
next
elseif   checkitem(id)   =   false   then
aryaddcart   =   session( "cart ")
newsize=ubound(aryaddcart,2)+1
redim   preserve   aryaddcart(5,newsize)
set   rs=fs.EXECute( "select   productname,picture,shi_price,hao_price   from   fs_product   where   id= "&id)
aryaddcart(0,newsize)   =   id
aryaddcart(1,newsize)   =   rs( "productname ")
aryaddcart(2,newsize)   =   rs( "picture ")
aryaddcart(3,newsize)   =   rs( "shi_price ")
aryaddcart(4,newsize)   =   rs( "hao_price ")
aryaddcart(5,newsize)   =   num
session( "cart ")   =   aryaddcart
set   rs=nothing
exit   sub
end   if
end   if
end   sub

发表于:2007-03-17 20:14:584楼 得分:0
汗     你这个更麻烦啊^^^^^而且我整套系统都采用的是我的那个数组   改的话工作量太大了^^^帮帮忙给看看拉     先谢谢了
发表于:2007-03-17 20:22:205楼 得分:0
不套用.里面也是现成的例子啊.结合你的实际再修改啊.

里面添加删除各种功能都有.


快速检索

最新资讯
热门点击