Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Option drop down loop


  • Please log in to reply

#1
KingTheoden

KingTheoden

    Member

  • 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}
<p>
  {if $obj->mLinkToPreviousPage}
  <a href="{$obj->mLinkToPreviousPage}">Previous page</a>
  {/if}

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

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

</p>
{/if}
{if $obj->mProducts}
<table class="product-list" border="0">
  <tbody>
  {section name=k loop=$obj->mProducts}
	{if $smarty.section.k.index % 2 == 0}
	<tr>
	{/if}
	  <td valign="top">
		<h3 class="product-title">
		  <a href="{$obj->mProducts[k].link_to_product}">
			{$obj->mProducts[k].name}
		  </a>
		</h3>
		<p>
		  {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}" />
		  </a>
		  {/if}
		  {$obj->mProducts[k].description}
		</p>
		<p class="section">
		  Price:
		  {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>
		  {else}
			<span class="price">{$obj->mProducts[k].price}</span>
		  {/if}
		</p>
		
		[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 !==
			  $obj->mProducts[k].attributes[1.index_prev].attribute_name}
			{$obj->mProducts[k].attributes[1].attribute_name}:
		  <select name="attr_{$obj->mProducts[k].attributes[1].attribute_name}">
		  {/if}
		  
			{* Generate a new option tag *}
			<option value="{$obj->mProducts[k].attributes[1].attribute_value}">
			  {$obj->mProducts[k].attributes[1].attribute_value}
			</option>
			
		  {* Close the select tag? *}
		  {if $smarty.section.1.last ||
			  $obj->mProducts[k].attributes[1].attribute_name !==
			  $obj->mProducts[k].attributes[1.index_next].attribute_name}
		  </select>
		  {/if}
			
		{/section}
		</p>		[/b]  
	  </td>
	{if $smarty.section.k.index % 2 != 0 && !$smarty.section.k.first ||
		$smarty.section.k.last}
	</tr>
	{/if}
  {/section}
  </tbody>
</table>
{/if}

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

Advertisements







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