473,465 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to develop "favorite" feature (put liked post into favorites list etc.)

ilya Kraft
134 New Member
Hello,

I need to develop "favorite" feature for my website. I'd like to use something similar to twitter. For example I have a page with lot's of different posts and then a link to "Favorite" post > If person clicks that link, post gets added to favorite list. How to develop something like this?

Additional - how can I change color of Favorited post say from white to yellow, so it indicates favorite posts for user.
Jun 13 '11 #1

✓ answered by Markus

Set up a table named something along the lines of 'user_favorites'. This table will contain two items:
  1. user_id: so we can grab the favorited data for some user;
  2. article_id: so we can later pull the relevant articles from your database.

Then you would build a simple database query that looks up data from your user_favorites table based on the user_id of the current user. From this data, you use the article_id data to query your articles table.

Now have a go and post back if you need help.

5 1916
Markus
6,050 Recognized Expert Expert
Set up a table named something along the lines of 'user_favorites'. This table will contain two items:
  1. user_id: so we can grab the favorited data for some user;
  2. article_id: so we can later pull the relevant articles from your database.

Then you would build a simple database query that looks up data from your user_favorites table based on the user_id of the current user. From this data, you use the article_id data to query your articles table.

Now have a go and post back if you need help.
Jun 13 '11 #2
ilya Kraft
134 New Member
Hi,

Thnx, Alright I tried it here is what I've got so far.

Expand|Select|Wrap|Line Numbers
  1. //I've gathered users I'd before and it is in $id variable
  2. //Now I select information from user_favorites
  3.  
  4. sql = ("SELECT * FROM user_favorites WHERE user_id=$id");
  5. while($row = mysql_fetch_array($sql)){ 
  6. $article_id=$row_["article_id"];
  7. }
  8.  
  9. //Then I select articles that have id that is equal
  10. //to $article_id
  11.  
  12. sql2 = ("SELECT * FROM articles WHERE id=$article_id");
  13.  
  14. //And then I just use while loop to gather info
  15.  
  16.  
Is this right approach to this? I haven't tried it yet, because I need to complete different areas before I can do this one ))) I asked question to be prepared )))
Jun 13 '11 #3
Markus
6,050 Recognized Expert Expert
The second SQL query would have to be part of your first while loop, otherwise, you'll only have to last article id.

Expand|Select|Wrap|Line Numbers
  1. loop over each article id where user_id = $id
  2.    select article from articles table where article id matches
  3. end loop
  4.  
That is the pseudo-code.
Jun 13 '11 #4
ilya Kraft
134 New Member
Wooh, Ok so it will have to look like this?

Expand|Select|Wrap|Line Numbers
  1. sql = ("SELECT * FROM user_favorites WHERE user_id=$id");
  2. while($row = mysql_fetch_array($sql)){ 
  3. $article_id=$row_["article_id"];
  4. sql2 = ("SELECT * FROM articles WHERE id=$article_id");
  5.  
  6. //And I will initialize variables like $article_body, $title right after second query, is it right?
  7.  
  8. }
  9.  
  10.  
Jun 13 '11 #5
Markus
6,050 Recognized Expert Expert
You would use the data from the second query within that loop, yes.
Jun 13 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: JP | last post by:
I have the need to be able to access the IE5+ favorites menu, read the title and URL for each shortcut so I can render the person's favorites list on a web page. The project I'm working on is...
8
by: sara | last post by:
I am learning Access and programming. I wanted to have the user select the departments for an ad from the list of all departments. Found code (that I could understand) on this site, and it works....
4
by: Dino Buljubasic | last post by:
A simple way to do this is VB.NET is like this: lvwIndex.Columns.Item(e.Column).Text = _ strColHeaderNOArrow & " " & ChrW(&H25B2) I tried to do the same in C# like: ...
1
by: Brian Kitt | last post by:
Over the years, from time to time, I've added a website as a 'favorite', and noticed that an icon (other than the standard ie icon) would be associated with it. Unfortunatley I don't have any of...
1
by: shengmin.ruan | last post by:
the wrong code is: public ref struct OutPacket{ int index; List<MainInfo^>^ mainInfos; }; public ref struct MainInfo{
1
by: The Facilitator | last post by:
Hello all, I am trying to find out what the field is in Outlook that holds all the people's email addresses for when the final completed task report is sent. Where is it and how can I access it...
2
by: David | last post by:
Hi With New Zealand POast changing the post codes, all organisations now need to update their databases. I work with a small not for profit and we need to update our access database. Does anyone...
2
by: sree12 | last post by:
Hi all, I want to develop a feature like intellisense. Please suggest me how to develop intellisense feature in "C++" or "VC++" in my own application. Any suggestions will be...
0
by: =?Utf-8?B?ZGIgY2hhbGxlbmdlZA==?= | last post by:
I am realy challenged by MSN Live. I was quite happy with my former hotmail. The new forced-upon-me version has caused me nothing but headaches and lots of work. It consumes huge amounts of my time...
2
by: raulbolanos | last post by:
Hello, I want to put some structure into a List. Therefore I dont know how to declare the type list.. maybe structureType and then add the structure into the list, for example; ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.