Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

"look ahead" in a section loop

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-26-2004, 11:07 AM
  jds580s's Avatar 
jds580s jds580s is offline
 

Advanced Member
  
Join Date: Oct 2004
Posts: 38
 

Default "look ahead" in a section loop

Not sure if this is possible with smarty but thought I would ask

I am displaying products in 3 columns sorted by manufacture.
I would like to place the product manufacture name at the beginning of each "section" of manufactures ASCII excample below

manufacture1---------
prod1 prod2 prod3
prod4 prod5
manufacture2---------
prod6 prod7 prod8
prod9
manufacture3---------
prod10

With lots of help from pmstudios the manufacture info for each product is displaying and the products are sorted in the correct order

My thought was to do something like
if product manufactureID is not equal to product_next manufactureID
output manufacture name

My question is in
{section name=product loop=$products}
can I "look ahead" to the next product in the loop to compare to the current product's manufacturer id?

Thanks!
__________________
animator for hire
onthez.com
------------------------
x-cart v4.0.5 Linux
_________________
Reply With Quote
  #2  
Old 10-26-2004, 01:04 PM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

Your best bet would be to build an associative array to loop over as it would make it alot easier to maintain and edit. You'll need to group your data into a per manufacturer basis and order by manufacturer.

Basic example of an associative array:

Code:
[root array] | [mfrid1 array] |->[product1 array] |->[product2 array] [mfrid2 array] |->[product1 array] |->[product2 array] |->[product3 array]
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #3  
Old 10-26-2004, 03:13 PM
 
pmstudios pmstudios is offline
 

Senior Member
  
Join Date: May 2004
Posts: 133
 

Default

Hey jds580s,

To do what you're describing now changes the previous stuff (actually a bit simpler).

Just replace the previous code in products.php with
Code:
# # Create manufacturers array # $query = func_query("SELECT manufacturerid, manufacturer FROM $sql_tbl[manufacturers]"); $smarty->assign("manufacturers", $manufacturers);

Then in your template you'll do something like this
Code:
{section name=id loop=$manufacturers} {$manufacturers[id].manufacturer} {section name=product loop=$products} {if $products[product].manufacturerid eq $manufacturers[id].manufacturerid} {$products[product].product} {/if} {/section} {/section}

Hope this helps....
__________________
X-Cart 4.0.5
MySQL: 3.23.58
PHP 4.3.2
Reply With Quote
  #4  
Old 10-26-2004, 03:20 PM
  jds580s's Avatar 
jds580s jds580s is offline
 

Advanced Member
  
Join Date: Oct 2004
Posts: 38
 

Default

Thanks Boomer and pmstudios.

pmstudios, I actually use what you helped me with earlier in another section of the cart. I was able to solve this issue in the template (well almost, I've still got a few things to work out) but it's 90% of the way there.

Code:
{*** ########## Manufacture Heading for products ########## ***} {assign var="manid" value=$products[product].manufacturerid} {if $manufacturers[$manid].manufacturerid ne $last_manufacturerid} {if $manufacturers[$manid].manufacturerid ne "0"} {if $first_product eq"false"} </td></tr><tr><td colspan="3"> <hr> {else} <td colspan="3"> {/if} {$manufacturers[$manid].manufacturer} {if $manufacturers[$manid].descr ne ""} <span class="maintext">{$manufacturers[$manid].descr} </span> {if $manufacturers[$manid].image ne ""} Manufacture Logo<hr> {/if}{/if}</td></tr><tr valign="top">{/if}{/if} {assign var="last_manufacturerid" value=$products[product].manufacturerid} {assign var="first_product" value="false"} {*** ########## End Manufacture Heading for products ########## ***}

My original approach of looking ahead seemed way to hard, but I thought, why look ahead when I can look back?!
I just set a variable towards the end of the loop that remembers what the manufacture was of the last product and if it is the same, it just skips the code.
__________________
animator for hire
onthez.com
------------------------
x-cart v4.0.5 Linux
_________________
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 02:59 PM.

   

 
X-Cart forums © 2001-2020