close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Sessions and recordset

Thread began 8/01/2010 3:29 am by victor405909 | Last modified 8/26/2010 10:22 pm by victor405909 | 3417 views | 15 replies

CraigRBeta Tester

In order to prove (to myself), I could do this, I produced the following on the product detail page, (which takes the url parameter ‘Item’).
It may need some tidying up, but it seems to work ok

This code creates an array stored as session variable to hold the last 6 itemid’s
The array is then sliced to remove the current itemid, so we end up with 5 elements for setting the criteria.
A criteria string is then built to append to the select statement, which returns 5 rows, for the last 5 items viewed.

(you could also do some further inspection of the array, to eliminate any duplicate key values, but i have't yet done this)

The only problem is in the order of the resulting rows.
I can’t think of a way to sort the rows in the order in which they were stored in the array.
Can anyone help with this, or come up with an alternative solution ?


<?php
if (!isset ($_SESSION["lastviewed"])) {//set up array to hold item id of selected products
$_SESSION["lastviewed"] = array();
}

if (isset($_GET['Item'])) {//adds a itemid to the array
if (count($_SESSION["lastviewed"]) <= 5) {//we only want 6 elements to the array, so add one if we currently have 5 or fewer
array_push($_SESSION["lastviewed"],(get_magic_quotes_gpc()) ? $_GET['Item'] : addslashes($_GET['Item']));//add the current itemid to the array
} else {
$_SESSION["lastviewed"] = array_slice($_SESSION["lastviewed"],1) ;// we have 6 elements already, so remove the first element of the array
array_push($_SESSION["lastviewed"],(get_magic_quotes_gpc()) ? $_GET['Item'] : addslashes($_GET['Item']));//add the current itemid to the array
}
}

//create the criteria string
$_SESSION["criteria"] = array_slice($_SESSION["lastviewed"],0,-1) ;// we don't want the current itemid, so remove the last element of the 'lastviewed' array

$stringcriteria = '';
foreach ($_SESSION["criteria"] as $key => $value) {//loop through the array to build the string to set the criteria
$stringcriteria = $stringcriteria.' OR ItemID = '.$value;

}
$stringcriteria = substr($stringcriteria,4) ;//the string needs to be trimmed, to remove ' OR ' from the beginning

mysql_select_db($databaseConnection, $Connection);
$query_rslastfiveviewed = "SELECT ItemID, ItemName, ItemImageURL, ItemThumbnailURL FROM tblitem WHERE ".$stringcriteria."";
$rslastfiveviewed = mysql_query($query_rslastfiveviewed, $Connection) or die(mysql_error());
$row_rslastfiveviewed = mysql_fetch_assoc($rslastfiveviewed);
$totalRows_rslastfiveviewed = mysql_num_rows($rslastfiveviewed);

?>


...add the appropriate code to the page to view the results

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...