Solved

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

Posted on 2010-09-07
13
385 Views
Last Modified: 2013-12-24
CFMX 7, Windows 2003, Mysql

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!

Thanks!
0
Comment
Question by:Bang-O-Matic
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 15

Expert Comment

by:Gurpreet Singh Randhawa
ID: 33623955
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!
0
 
LVL 3

Expert Comment

by:Gjslick
ID: 33623958
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>

Hope that helps!
0
 
LVL 15

Expert Comment

by:Gurpreet Singh Randhawa
ID: 33623981
Maintaining Cookies can be cumbersome if you have a big list of details for your favorite list!

Cookies can be used and a combination of cookie/database can help you in building a better system, if yuou still reply on COOKIES, that has many disadvantages,

Some browers do not allow cookies as it might have been disabled by the user on his/her machine!

sometimes the website gets blocked due to heavy usage of cookies.
0
 

Author Comment

by:Bang-O-Matic
ID: 33627807
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>

Open in new window

0
 
LVL 25

Expert Comment

by:dgrafx
ID: 33628330
in ColdFusion you need to surround code with <cfoutput> tags.
if you do not then you will see #variable# instead of the variables value.

just for simplicities sake - add <cfoutput> at the very beginning of your page and </cfoutput> at the very end and then try it

Also it looks like you want to use MLSID instead of RealID and ADDRESS instead of RealName - just swap out the names - simple as that!

good luck ...
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 33628351
oh - and very important - this method uses ONE cookie - just to clarify ...
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Bang-O-Matic
ID: 33629076
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?

<cfloop list="#cookie.favpage#" index="ii">
<a href="yourrealestatepage.cfm?MLSID=#listfirst(ii,"|")#" class="smallgraytext">#listlast(ii,"|")#</a>
| <a href="addfavorites.cfm?favID=#MLSID#|#StreetNumber# #Street#" target="hide"><cfif listfindnocase(cookie.favpage,"#MLSID#|#trim(Street)#")>Remove From Favorites<cfelse>Add To Favorites</cfif></a>
<br>
</cfloop>

0
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 33629616
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 ...

<a href="addfavorites.cfm?favID=#MLSID#|#(StreetNumber)# #trim(Street)#" target="hide"><cfif listfindnocase(cookie.favpage,"#MLSID#|#trim(StreetNumber)# #trim(Street)#")>Remove From Favorites<cfelse>Add To Favorites</cfif></a>

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.
0
 

Author Comment

by:Bang-O-Matic
ID: 33630805
"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.

Thanks!
screenshot.gif
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 33630918
i assumed you have a list of properties where the links normally reside
then if a person clicks a property they are then taken to a details page that has just the one property ........
0
 

Author Comment

by:Bang-O-Matic
ID: 33631341
Oh I see what you are saying now, and yes I do have details page where the link, as you explained above, would work.
Is there any way to add a remove link to thefavs loop as pictured??

 I know you have answered the original question and I will give you the points.  
0
 

Author Closing Comment

by:Bang-O-Matic
ID: 33631369
thanks!
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 33632742
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

How to run any project with ease

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

Join & Write a Comment

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 …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now