greg Posted October 27, 2008 Share Posted October 27, 2008 Sorry, I'm new to php and I need some help. I have the following code to return the recent products viewed by visitors. I want to return these values, EXCEPT the last product viewed. Could anyone help me please. Thanks Link to comment https://forums.phpfreaks.com/topic/130296-solved-returning-values-problem-please-help/ Share on other sites More sharing options...
MadTechie Posted October 27, 2008 Share Posted October 27, 2008 hummm.. and the code is ? Link to comment https://forums.phpfreaks.com/topic/130296-solved-returning-values-problem-please-help/#findComment-675730 Share on other sites More sharing options...
greg Posted October 27, 2008 Author Share Posted October 27, 2008 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 ; ?> Link to comment https://forums.phpfreaks.com/topic/130296-solved-returning-values-problem-please-help/#findComment-675754 Share on other sites More sharing options...
MadTechie Posted October 27, 2008 Share Posted October 27, 2008 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; Link to comment https://forums.phpfreaks.com/topic/130296-solved-returning-values-problem-please-help/#findComment-675785 Share on other sites More sharing options...
greg Posted October 27, 2008 Author Share Posted October 27, 2008 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); Link to comment https://forums.phpfreaks.com/topic/130296-solved-returning-values-problem-please-help/#findComment-675870 Share on other sites More sharing options...
MadTechie Posted October 27, 2008 Share Posted October 27, 2008 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']; } ?> Link to comment https://forums.phpfreaks.com/topic/130296-solved-returning-values-problem-please-help/#findComment-676170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.