Jump to content

Lists/Database (Favourite System) help


Mutley

Recommended Posts

I'm wanting to make a "favourite" system for my site for articles, so members can add the article to their accounts favourites by clicking a button.

I'm unsure what is the easiest way to do this. I'm thinking if I have 2 fields in the database (username and favourites) then in the favourites field have a list of all the favourites so (article1, article8, article11, article12) etc by the username fields side.

Just, how do I explode the list into individual words if I want to list them like:
article1
article8
article11
article12

in a table? Do I use an array function of some sort?

And finally, how do I insert data into the field with out overwriting what is currently their? So If I add "article20" it adds it to the end of the list in the field?

Is this a good way to do it?

Thanks. :)
Link to comment
Share on other sites

well you could just use something like preg_replace() to replace commars with </tr><tr> to create a new row in a table.

also when adding a new one just create a new variable and add ",$newfavourite" onto the old variable.

But a better way I would think to do it was to add a table with the columns username and article and just get it to list all results matching that username. That way you can just put a new entry in the table every time they add a new one?
Link to comment
Share on other sites

[quote author=thorpe link=topic=122012.msg502586#msg502586 date=1168552821]
Create a table with user ids (or names) and a field fav. Then just add a new record for each favourite. To get all user 4's favourites run...

[code]
SELECT fav FROM favourites WHERE userid = 4;
[/code]
[/quote]

How does this differ from viewing or adding any information to the database?

So how do I POST a new favourite, is it simply an INSERT INTO ? How do I insert it into the same field?
Link to comment
Share on other sites

And if you do something like:

[code]while($row=mysql_fetch_array($query)){

$favourite = $row['favourite'];

echo "$favourite <br>";

}[/code]

It should list all of the records for that user. Just use that as an example and build from it to suit your needs.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.