• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

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

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
Bang-O-Matic
Asked:
Bang-O-Matic
  • 5
  • 5
  • 2
  • +1
1 Solution
 
Gurpreet Singh RandhawaWeb DeveloperCommented:
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
 
GjslickCommented:
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
 
Gurpreet Singh RandhawaWeb DeveloperCommented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Bang-O-MaticAuthor Commented:
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
 
dgrafxCommented:
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
 
dgrafxCommented:
oh - and very important - this method uses ONE cookie - just to clarify ...
0
 
Bang-O-MaticAuthor Commented:
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
 
dgrafxCommented:
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
 
Bang-O-MaticAuthor Commented:
"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
 
dgrafxCommented:
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
 
Bang-O-MaticAuthor Commented:
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
 
Bang-O-MaticAuthor Commented:
thanks!
0
 
dgrafxCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 5
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now