Coldfusion , How to build a "save as favorite" items list.

On my real estate listings site I want the prospect to be able to save properties as favorites on a cookie by clicking an "add" or "remove" link on my results page and then output the favorites on my page as a link : MLSID | StreetNumber StreetName

Is there any simple way to accomplish this? code examples appreciated!

I suggest you use Database tables for this! There are many advantages to it!

1) You can manipulate them from admin panel for any user
2) Different members will have different kinds of bookmarks stored for them.
3) They can enable/disable the favorites if they want to view or not in their members area!
4) Deletion of links is possible.
5) You can count the visits of each link visited and track its most visited and can also add it to the top.
6) you can display the count against it.

7) and much more, that can help you build a better save as favorite list!

Same Example could be like this!

CREATE TABLE `zimyellowpages`.`favorites` (

`fav_key` INT NOT NULL ,

`FavoriteName` VARCHAR(255) NULL ,

`visits` INT NULL DEFAULT 0 ,

`favoriteURL` VARCHAR(255) NULL ,

`isOpera` VARCHAR(45) NULL ,

`isMozilla` VARCHAR(45) NULL ,

`isChrome` VARCHAR(45) NULL ,

`isMSIE` VARCHAR(45) NULL ,

PRIMARY KEY (`fav_key`) ,

UNIQUE INDEX `FavoriteName_UNIQUE` (`FavoriteName` ASC) )

ENGINE = InnoDB;

now you can create your coldfusion code where you can manipulate everything, you can also store cookies in your system!

Hey, very simple if you just want to store the data in a cookie. You can set a cookie using the <cfcookie> tag.

If you want this cookie to last, maintaining the user's favorites list between browser sessions, your cfm code would set the cookie on the client's browser like this:
<cfif not isDefined( 'cookie.favorites' )>
<cfcookie name="favorites" expires="never" value="">
</cfif>

Putting the above code in your Application.cfm file, or in the onRequestStart() method of an Application.cfc file would definitely be useful, to make sure that the cookie is always created when the user first comes to any of the pages on your site.

Then, if you are having the client submit a list of favorites, you can store the entire list in the cookie by using the cookie scope.
Ex: <cfset cookie.favorites = "1,2,3,4,5,6">
Ex: <cfset cookie.favorites = form.favorites>
etc.

When you want to read back each individual favorite in the cookie, you can treat it just like any other variable:
<cfloop list="#cookie.favorites#" index="favorite">
<cfoutput>#favorite#</cfoutput><br>
</cfloop>

Since I'm not a programmer and know very little about cfml, I'd like to stick with the quickest and easiest method of accomplishing this task. then build on that (maybe incorporating the database) once I have some working code and understand whats going on. I had posed this same question a couple yrs back here, and got a solution that seemed simple enough but didn't completely work, for me. the code I'm working with is attached below and was written by dgrafx . I got the cookie set on my results.cfm page and built the addfavorites.cfm page and have the "add or remove" links showing up on my results .cfm page but when i click to add a fav, the resulting link shows up but does not carry over my MLSID | ADDRESS it just looks like this on the page : #listlast(ii,"|")# and the url is yourrealestatepage.cfm?RealID=#listfirst(ii,

How can I work my MLSID and ADDRESS variables into this code?

<!---on my results.cfm page--->
<cfif Not structkeyexists(cookie,"favpage")>
<cfset cookie.favpage="">
</cfif>
<!---make the add or remove link for each record displayed--->
show a link that says "Add to favorites" or "Remove from fav" like this:
<a href="addfavorites.cfm?favID=#RealID#|#trim(RealName)#" target="hide"><cfif listfindnocase(cookie.favpage,"#RealID#|#trim(RealName)#")>Remove From Favorites<cfelse>Add To Favorites</cfif></a>
<!---you see how the target is "hide"
create a zero size iframe-the reason is so that they don't leave the page when clicking the add link.--->
<iframe name="hide" id="hide" style="height:0px;width:0px;"></iframe>
<!---Then on addfavorites.cfm--->
<cfif structkeyexists(url,"favID")>
<cfif NOT listfindnocase(cookie.favpage,favID)>
<cfcookie name="favpage" value="#ListAppend(cookie.favpage,favID)#" expires="30"><!--- adds to if not there already --->
<cfelse>
<cfcookie name="favpage" value="#ListDeleteAt(cookie.favpage,listfind(cookie.favpage,favID))#" expires="30"><!--- deletes if there already --->
</cfif>
</cfif>
<!---then on your left nav you do:--->
<cfloop list="#cookie.favpage#" index="ii">
<a href="yourrealestatepage.cfm?RealID=#listfirst(ii,"|")#">#listlast(ii,"|")#</a><br>
</cfloop>

Thanks Its working! one more small detail, how would I put a "remove" link beside each property on the output list of favs? it works but the only way to remove from favs is the go back and find the property and click remove. would I just add the add remove link like this?

you do it the same as the other page except you don't loop through your cookie
you just have the link to addfavorites.cfm and for the text of the link you simply say
if listfindnocase(cookie.favpage etc ...

note that in order for this to work you need to send into addfavorites.cfm the EXACT same string as what you are testing for with the listfindnocase(cookie.favpage,"?????")

you CANNOT add mlsid & streetnumber & street then check for something different - it looks like you are checking then for mlsid & street
this will always result in a difference ...

ALSO note that Trim() is a big deal!
if you trim on one side of an equation you nearly always ( depending on what you are doing ) trim on the other side or chances are you will get differences!
A good practice is to trim when inserting or updating you database as well.

"you do it the same as the other page except you don't loop through your cookie
you just have the link to addfavorites.cfm and for the text of the link you simply say
if listfindnocase(cookie.favpage etc ..."

Please pardon me but I don't understand...If I dont have it in the loop, how would I get a "remove" link for each saved property that was output in the loop? Attached is a screenshot note the "My Favorites" at the bottom right what I need is a remove link beside each favorite.

you mean where it says My Favorites ?
yes - just do it with the loop as stated above - I believe you were on the right track you just really need to pay attention to the notes i posted like check for the same thing you are inserting and trim etc ...
my response above meant to remove one single link that was on a detail page - like for example right by the property title

note: if this is a site where you have prospects sign in for any reason then i would eventually move this feature to a database feature.
same concept but a bit easier to manage and favs will last forever (or until deleted)
the cookie method you are using is fine for a simple solution but at any time IE (or any browser) could decide to delete your prospects cookie.favpage and of course then prospect will be mad at your site "crummy site - can't even keep track of a few properties"
C'est la vie ...

0

Featured Post

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Foreword
In the years since this article was written, numerous hacking attacks have targeted password-protected web sites. The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided. Of cou…

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs. This Article is intended to be a resource for such a task.
Preface
The other day, I was involved …