Jump to content

[SOLVED] Returning values problem - please help


greg

Recommended Posts

OH my God!!!  ... here is it.

if (!tep_session_is_registered('recently_viewed'))
	{
	tep_session_register('recently_viewed');
	$recently_viewed = $HTTP_GET_VARS['products_id'] . ';';
	}
$check_not_duplicate = $HTTP_GET_VARS['products_id'];
$temp_recent = $recently_viewed;
if (!ereg($check_not_duplicate, $temp_recent ) )
 	$recently_viewed = $HTTP_GET_VARS['products_id'] . ';' . $recently_viewed ;
?>

you mean something like this

<?php
if (!isset($_SESSION['recently_viewed']) )
{
      //set session as array
      $_SESSION['recently_viewed'] = array();
}
//add to array
$_SESSION['recently_viewed'][] = $HTTP_GET_VARS['products_id'];
//remove dups
$_SESSION['recently_viewed'] = array_unique($_SESSION['recently_viewed']);
?>

//remove last item
$tmp = array_pop($tmp);
//create ; delimited string
$tmp = implode(";",$tmp);
//display string
echo $tmp;

Thank you MadTechie.

I still have a little problem with this. The first part produce only one value in the array, the last product viewed.

On the second part, I don't get any results at all. This is what I did:

//remove last item

$tmp = array_pop($_SESSION['recently_viewed']);

//create ; delimited string

$tmp = implode(";",$_SESSION['recently_viewed']);

//display string

echo $tmp;

 

I think may be the other part of the code has something to change but I don't know how do it.

 

Thank you for your help.

 

Greg

 

new WhatsNewBoxHeading($info_box_contents, false, false);

    $counter = 0;
    $info_box_contents = array();
    $recent_products = split(';',$recently_viewed);
    $rows=0;
    $cols=0;
$total=(MAX_ROWS*MAX_COLS); 

   foreach ($recent_products as $recent)
   {  
   if ((strlen($recent) >0) && ($counter < $total) && ($rows<MAX_ROWS))
	   {
      $recent_info = tep_db_query("select  p.products_image from " . TABLE_PRODUCTS . " p where p.products_id = '" . $recent. "'");
      $recent_info_values = tep_db_fetch_array($recent_info);
      $counter++;
      if (strlen($counter) < 2)
	  {
        $counter = '0' . $counter;
	  }
      $info_box_contents[$rows][$cols] = array('align' => 'left',
                            'params' =>'valign="top" class="productListing-data"',                                 
						'text'  => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $recent, 'NONSSL') . '">' .
tep_image(DIR_WS_IMAGES . $recent_info_values['products_image'], 
tep_get_products_name($recent)) . '</a><br>' . $counter . '. ' . tep_get_products_name($recent));
      $cols++;
      if ($cols >= MAX_COLS)
	  {
        $cols = 0;
        $rows++;
	  }
	  }
   }    
new tableBox($info_box_contents,true);

Heres a quick script to show how i would use it..

Please note i upgraded 
$HTTP_GET_VARS to $_GET and
changed the way sessions are called

i also added some emulation to save entering lots of different URLs but it grabs the first one

[code?tester.php?products_id=123456789]
<?php
session_start();
Add(); //Grab First one from URL
echo "<br>---<br>";

/*EMULATE START -- remove from live code*/
$_GET['products_id'] = 1; //emulate new entry
Add();
echo "<br>---<br>";
$_GET['products_id'] = 2; //emulate new entry
Add();
echo "<br>---<br>";
$_GET['products_id'] = 4; //emulate new entry
Add();
echo "<br>---<br>";
$_GET['products_id'] = 8; //emulate new entry
Add();
echo "<br>---<br>";
$_GET['products_id'] = 10; //emulate new entry
Add();
echo "<br>---<br>";
$_GET['products_id'] = 20; //emulate new entry
Add();
echo "<br>---<br>";
/*EMULATE END*/

$tmp = $_SESSION['recently_viewed'];
//remove last item
array_pop($_SESSION['recently_viewed']);
//create ; delimited string
$tmp = implode(";",$tmp);
//display string
echo $tmp;

//reset (comment out to keep them)
#unset($_SESSION['recently_viewed']);

function Add()
{
if (!isset($_SESSION['recently_viewed']) )
{
      //set session as array
      $_SESSION['recently_viewed'] = array();
}
//add to array
$_SESSION['recently_viewed'][] = $_GET['products_id'];
//remove dups
$_SESSION['recently_viewed'] = array_unique($_SESSION['recently_viewed']);
echo "Added:->".$_GET['products_id'];
}


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.