[thelist] CF_Shoppingcart, aligning lists (REPOST?)

.jeff jeff at members.evolt.org
Thu Jul 12 23:08:12 CDT 2001


nick,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: Nick Boyce
:
: item: 31,141,66
: qty:  1,1,3
:
: Which means that I have one of item 31, one
: of item 141 and 3 of item 66.  Their order on
: this list is defined by whe they were added.
: Everything is fine so far. Still with me?
:
: I want to grab those ids and use them in a
: query. Here is how I am doing it (modulesnip
: is actually the name btw):
:
: <cfif shoppingcart_items gte 1>
:   <cfquery name=getall datasource="#db#">
:     select moduleid,
:            modulesnip
:       from module
:      where moduleid in (#shoppingcart_product#)
:   </cfquery>
: </cfif>
:
: Thats grabs the output fine, but outputs them
: ordered by moduleid asc. So when I go to output
: them in  loop, the orders dont align. Using the
: above example, it outputs in this order: 31,66,141
: when I really want it in this order 31,141,66. I
: really dont know enough about lists to know if I
: am using this correctly, but I just can't think
: of a way to make the orders align.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sounds to me like you'll have to get funky with the query to make this work.
how about something like this:

<cfif Val(shoppingcart_items)>
  <cfquery name="getall" datasource="#db#">
    SELECT moduleid,
           modulesnip,
           (SELECT 1
              FROM module) AS quantity
      FROM module
     WHERE moduleid IN (#shoppingcart_product#)
  </cfquery>
</cfif>

you'll end up with a query with a quantity column that has values of 1 all
the way across.  now, we've gotta go through that query and reassign the
values of that column with the appropriate quantity.

<cfloop from="1" to="#getall.recordcount#" index="currentrow">
  <cfset quantity = ListGetAt(qty, ListFind(item,
getall["id"][currentrow]))>
  <cfset getall["quantity"][currentrow] = quantity>
</cfloop>

now, when it comes time to display this information, your quantities will be
with the right products.

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/






More information about the thelist mailing list