Page 1 of 1
displaying duplicate items
Posted: Wed Jun 25, 2008 9:12 am
by littlebeagle
Hi,
I'm trying to help a friend with a shopping cart (Shop-Script Premium), and on the main page, it is supposed to show 4 random products. The problem is that it displays duplicates sometimes (same product side by side). Can anyone tell me how to fix this?
His site is:
http://www.lambofgodjewelry.com
Thanks.
Re: displaying duplicate items
Posted: Wed Jun 25, 2008 10:02 pm
by Zoxive
We can't really help without seeing the code that is generating the random items.
The community has yet to acquire the ability to read minds, and guess each others code.
Re: displaying duplicate items
Posted: Wed Jun 25, 2008 10:22 pm
by littlebeagle
Sorry, I wasn't sure if it was something someone would just *know* or could figure out by 'View Source' in the browser. I'm not a PHP person myself.
Here is the code I think you need. If not, then please let me know.
(the 4 products being shown are referenced as "special offers" in the shopping cart.)
Thanks so much for your help.
Code: Select all
<p style="margin-top: 0; margin-bottom: 0">{* front-end homepage*}
{$smarty.const.STRING_GREETINGS}
</p>
<p style="margin-top: 0; margin-bottom: 0">
<div align="center">
<table border="1" width="402" id="table45" cellspacing="0" cellpadding="0" style="border-width: 0px">
<tr>
<td style="border-style: none; border-width: medium" valign="top"><p style="margin-top: 0; margin-bottom: 0">
<font size="2">{* show two random products from the special offers list *}
</font>
</p>
<p align="right" style="margin-top: 0; margin-bottom: 0">
<font size="2">{counter name='special_offers_count' start=0 skip=1 print=false}
{section name=i loop=$special_offers}
{counter name=special_offers_count print=false}
{/section}
{counter name=special_offers_count assign="special_offers_count"}
{if $special_offers_count > 1}
{math equation="rand() % (maximum-1)" maximum=$special_offers_count assign="special_offers_random_index"}
{math equation="(n+1)%(m-1)" n=$special_offers_random_index m=$special_offers_count assign="special_offers_random_index2"}
</font>
<TABLE width="190" CELLPADDING=0 CELLSPACING="1" id="table46">
<TR><TD>
<table border=0 width=200 id="table47" background="images/prod-brief-210.jpg" cellspacing="0" cellpadding="0">
<tr>
<td align=center valign="top" background="images/yellow-blue-border-thin.jpg">
<p style="margin-top: 0; margin-bottom: 0">
<img src="images/prod-brief-top210.jpg" align="top"></td>
</tr>
<tr>
<td align=center background="images/yellow-blue-border-thin.jpg">
<p style="margin-top: 0; margin-bottom: 0"><a href="index.php?productID={$special_offers[$special_offers_random_index][0]}"><img src="products_pictures/{$special_offers[$special_offers_random_index][2]}" border=0 width="100"></a></td>
</tr>
<tr>
<td align=center background="images/prod-brief-210.jpg">
<p style="margin-top: 0; margin-bottom: 0"><a href="index.php?productID={$special_offers[$special_offers_random_index][0]}">
<font size="2" face="Arial" color="#C2D6F3">{$special_offers[$special_offers_random_index][1]}</font></a></td>
</tr>
<tr>
<td align=center background="images/prod-brief-210.jpg">
<p style="margin-top: 0; margin-bottom: 0">
<font color=#FFDD8A size="2" face="Arial"><b>
{$special_offers[$special_offers_random_index][3]}</b></font></td>
</tr>
<tr>
<td align=center valign="bottom" background="images/yellow-blue-border-thin.jpg">
<p style="margin-top: 0; margin-bottom: 0">
<img src="images/prod-brief-bottom210.jpg" align="top"></td>
</tr>
</table>
</TD></TR></TABLE>
<p style="margin-top: 0; margin-bottom: 0">{if $special_offers_random_index ne $special_offers_random_index2}</p>
<P align="center" style="margin-top: 0; margin-bottom: 0">
<TABLE width="200" CELLPADDING=0 CELLSPACING="1" id="table48">
<TR><TD>
<table border=0 width=200 background="images/prod-brief-210.jpg" cellspacing="0" cellpadding="0" id="table49">
<tr>
<td align=center>
<p style="margin-top: 0; margin-bottom: 0">
<img src="images/prod-brief-top210.jpg" align="top"></td>
</tr>
<tr>
<td align=center>
<p style="margin-top: 0; margin-bottom: 0"><a href="index.php?productID={$special_offers[$special_offers_random_index2][0]}"><img src="products_pictures/{$special_offers[$special_offers_random_index2][2]}" border=0 width="100"></a></td>
</tr>
<tr>
<td align=center background="images/prod-brief-210.jpg">
<p style="margin-top: 0; margin-bottom: 0"><a href="index.php?productID={$special_offers[$special_offers_random_index2][0]}">
<font color="#C2D6F3" face="Arial" size="2">{$special_offers[$special_offers_random_index2][1]}</font></a></td>
</tr>
<tr>
<td align=center background="images/prod-brief-210.jpg">
<p style="margin-top: 0; margin-bottom: 0">
<font color=#FFDD8A face="Arial" size="2"><b>
{$special_offers[$special_offers_random_index2][3]}</b></font></td>
</tr>
<tr>
<td align=center>
<p style="margin-top: 0; margin-bottom: 0">
<img src="images/prod-brief-bottom210.jpg" align="top"></td>
</tr>
</table>
</TD></TR></TABLE>
<p style="margin-top: 0; margin-bottom: 0">{/if} {/if} {* end of special offers*}
</p>
<P style="margin-top: 0; margin-bottom: 0"></P>
<p style="margin-top: 0; margin-bottom: 0"></td>
<td style="border-style: none">
<p style="margin-top: 0; margin-bottom: 0">
<font size="2">{* show two random products from the special offers list *}
</font>
</p>
<p align="right" style="margin-top: 0; margin-bottom: 0">
<font size="2">
{*this part of code caused doubled products in the special offers :: begin*}
{*counter name='special_offers_count' start=0 skip=1 print=false}
{section name=i loop=$special_offers}
{counter name=special_offers_count print=false}
{/section}
{counter name=special_offers_count assign="special_offers_count"*}
{*this part of code caused doubled products in the special offers :: end*}
{if $special_offers_count > 1}
{math equation="rand() % (maximum-1)" maximum=$special_offers_count assign="special_offers_random_index"}
{math equation="(n+1)%(m-1)" n=$special_offers_random_index m=$special_offers_count assign="special_offers_random_index2"}
</font>
<TABLE width="190" CELLPADDING=0 CELLSPACING="1"" id="table50">
<TR><TD>
<table border=0 width=200 background="images/prod-brief-210.jpg" cellspacing="0" cellpadding="0" id="table51">
<tr>
<td align=center valign="top" background="images/yellow-blue-border-thin.jpg">
<p style="margin-top: 0; margin-bottom: 0">
<img src="images/prod-brief-top210.jpg" align="top"></td>
</tr>
<tr>
<td align=center background="images/yellow-blue-border-thin.jpg">
<p style="margin-top: 0; margin-bottom: 0"><a href="index.php?productID={$special_offers[$special_offers_random_index][0]}"><img src="products_pictures/{$special_offers[$special_offers_random_index][2]}" border=0 width="100"></a></td>
</tr>
<tr>
<td align=center background="images/prod-brief-210.jpg">
<p style="margin-top: 0; margin-bottom: 0"><a href="index.php?productID={$special_offers[$special_offers_random_index][0]}">
<font size="2" face="Arial" color="#C2D6F3">{$special_offers[$special_offers_random_index][1]}</font></a></td>
</tr>
<tr>
<td align=center background="images/prod-brief-210.jpg">
<p style="margin-top: 0; margin-bottom: 0">
<font color=#FFDD8A size="2" face="Arial"><b>
{$special_offers[$special_offers_random_index][3]}</b></font></td>
</tr>
<tr>
<td align=center valign="bottom" background="images/yellow-blue-border-thin.jpg">
<p style="margin-top: 0; margin-bottom: 0">
<img src="images/prod-brief-bottom210.jpg" align="top"></td>
</tr>
</table>
</TD></TR></TABLE>
<p style="margin-top: 0; margin-bottom: 0">{if $special_offers_random_index ne $special_offers_random_index2}</p>
<P align="center" style="margin-top: 0; margin-bottom: 0">
<TABLE width="200" CELLPADDING=0 CELLSPACING="1" id="table52">
<TR><TD>
<table border=0 width=200 background="images/prod-brief-210.jpg" cellspacing="0" cellpadding="0" id="table53">
<tr>
<td align=center>
<p style="margin-top: 0; margin-bottom: 0">
<img src="images/prod-brief-top210.jpg" align="top"></td>
</tr>
<tr>
<td align=center>
<p style="margin-top: 0; margin-bottom: 0"><a href="index.php?productID={$special_offers[$special_offers_random_index2][0]}"><img src="products_pictures/{$special_offers[$special_offers_random_index2][2]}" border=0 width="100"></a></td>
</tr>
<tr>
<td align=center background="images/prod-brief-210.jpg">
<p style="margin-top: 0; margin-bottom: 0"><a href="index.php?productID={$special_offers[$special_offers_random_index2][0]}">
<font color="#C2D6F3" face="Arial" size="2">{$special_offers[$special_offers_random_index2][1]}</font></a></td>
</tr>
<tr>
<td align=center background="images/prod-brief-210.jpg">
<p style="margin-top: 0; margin-bottom: 0">
<font color=#FFDD8A face="Arial" size="2"><b>
{$special_offers[$special_offers_random_index2][3]}</b></font></td>
</tr>
<tr>
<td align=center>
<p style="margin-top: 0; margin-bottom: 0">
<img src="images/prod-brief-bottom210.jpg" align="top"></td>
</tr>
</table>
</TD></TR></TABLE>
<p style="margin-top: 0; margin-bottom: 0">
{/if}
{/if}
{* end of special offers*}
</p>
<p style="margin-top: 0; margin-bottom: 0"></td>
</tr>
</table>
</div>