Jump to content

Recently Viewed Items


JordanSmith

Recommended Posts

Hi Guys,

 

I have a script that shows the user of my shop what they have looked at. I was wondering if someone can tell me how I can limit this so it only lists 10 and no more.

 

Here is the code:

 

if(RECENTVIEWED ==1)
	{
		if(isset($_COOKIE['jimbeam'])){
			$productUrl = SITE_URL."ecom/index.php?action=ecom.pdetails&mode=";
			$productUrl = $this->libFunc->m_safeUrl($productUrl);

		 foreach ($_COOKIE['jimbeam'] as $name => $value)
    		{
    			$this->obDb->query="SELECT vTitle FROM ".PRODUCTS." WHERE vSeoTitle = '".$value."'";
				$rsProd = $this->obDb->fetchQuery();
    			$this->obTpl->set_var("TPL_VAR_PRODUCTTITLE",stripslashes($rsProd[0]->vTitle));
				$this->obTpl->set_var("TPL_VAR_PRODUCTURL",$productUrl.$value);
				$this->obTpl->parse("recent_blk","TPL_RECENT_BLK",true);
    		}
			$this->obTpl->parse("mainrecent_blk","TPL_MAINRECENT_BLK");			
		}

	}

 

Thanks,

Jordan

Link to comment
Share on other sites

Whoops, didn't notice it was in a foreach loop. Which by the way is very inefficient design. You should be able to use this code to run the same query outside of the foreach loop, so you have one query instead of 10.

 

$cookie = array_slice($_COOKIE['jimbean'], 0, 10);

$where = array();

foreach($cookie as $c)
{
$where[] = "'$c'";
}

$where = implode(', ', $where);

$this->obDb->query="SELECT vTitle FROM ".PRODUCTS." WHERE vSeoTitle IN($where) LIMIT 10";

 

Also, depending on how your database class works this may be susceptible to SQL injection.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.