I'm really trying to work out the best approach to creating an add to shortlist option on a clients realestate website.
This link http://www.harcourts.com.au/Property/Residential looks good, and to me it appears to be using a table to 开发者_Go百科storre the data, thats when i thought of maybe using the users ip address to store their data for 30days.
But then the problem would be that if 5 computers are on one ISP then they would have the same shortlists.
I then thought jquery would be good but i have not done anything of that sort before.
If anyone could please provide me a simple php mysql or jquery example of adding unique id's to a shortlist cache or cookie or session that would be great.
PS: I have only beginners knowledge so if examples could be posted or linked I will definitely learn it, not just copy and paste and forget. :-)
Thanks in advance.
You could create a cookie with a 30 day expiry which has a randomly generated id that you use to link to rows in your database.
Initialisation:
if( !isset( $_COOKIE['listid'] ) )
{
$listid = md5( time() ); // Should make sure this is unique
setcookie( 'listid', $listid , time()+60*60*24*30 );
}
else
{
$listid = $_COOKIE['listid'];
}
Adding an item:
mysql_query( 'INSERT INTO `table` ( `listid`, `itemid`) VALUES ("' . $listid . '","' . $itemid . '");' );
Retrieving items:
$q = mysql_query( 'SELECT `itemid` from `table` WHERE `listid` = "' . $listid . '"' );
while( $r = mysql_fetch_assoc( $q ) )
{
$items[] = $r;
}
This is a very basic solution, you would need to build on it to get exactly what you want.
精彩评论