Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

Option drop down loop

  • Please log in to reply




  • Member
  • PipPip
  • 21 posts
This one is worth two gold stars.

I am working out of Cristian Darie's PHP and MySQL Ecommerce 2nd edition book and am woefully stuck on chapter 6. For some reason, on the main page load (i.e., index pulling in products_list.tpl) I am getting a repeating option dropdown and all of the choices are a single attribute.

Attached is a picture of the problem. Also, the following is, what I believe, is the relevant code:

{* products_list.tpl *}
{load_presentation_object filename="products_list" assign="obj"}
{if $obj->mrTotalPages > 1}
  {if $obj->mLinkToPreviousPage}
  <a href="{$obj->mLinkToPreviousPage}">Previous page</a>

  {section name=m loop=$obj->mProductListPages}
	{if $obj->mPage eq $smarty.section.m.index_next}
	<a href="{$obj->mProductListPages[m]}">{$smarty.section.m.index_next}</a>

  {if $obj->mLinkToNextPage}
  <a href="{$obj->mLinkToNextPage}">Next page</a>

{if $obj->mProducts}
<table class="product-list" border="0">
  {section name=k loop=$obj->mProducts}
	{if $smarty.section.k.index % 2 == 0}
	  <td valign="top">
		<h3 class="product-title">
		  <a href="{$obj->mProducts[k].link_to_product}">
		  {if $obj->mProducts[k].thumbnail neq ""}
		  <a href="{$obj->mProducts[k].link_to_product}">
			<img src="{$obj->mProducts[k].thumbnail}"
			 alt="{$obj->mProducts[k].name}" />
		<p class="section">
		  {if $obj->mProducts[k].discounted_price != 0}
			<span class="old-price">{$obj->mProducts[k].price}</span>
			<span class="price">{$obj->mProducts[k].discounted_price}</span>
			<span class="price">{$obj->mProducts[k].price}</span>
		[b]{* Generate the list of attribute values *}
		<p class="attributes">
		{* Parse the list of attributes and attribute values *}
		{section name=1 loop=$obj->mProducts[k].attributes}
		  {* Generate a new select tag? *}
		  {if $smarty.section.1.first ||
			  $obj->mProducts[k].attributes[1].attribute_name !==
		  <select name="attr_{$obj->mProducts[k].attributes[1].attribute_name}">
			{* Generate a new option tag *}
			<option value="{$obj->mProducts[k].attributes[1].attribute_value}">
		  {* Close the select tag? *}
		  {if $smarty.section.1.last ||
			  $obj->mProducts[k].attributes[1].attribute_name !==
		</p>		[/b]  
	{if $smarty.section.k.index % 2 != 0 && !$smarty.section.k.first ||

I am 99% sure the SQL is good because, for starters, I did queries in phpMyadmin and everything was functioning well. Also, on a single product page, the two drop downs are perfectly rendered. There is little doubt that the problem is in this darn tpl file...

I've been up for a while playing with this, but it is time for church for a while! Major kudos to the person who can solve this quandary!

Attached Thumbnails

  • looping_errorTShirtShop.jpg

Edited by KingTheoden, 19 October 2008 - 05:53 AM.

  • 0


Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP