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
https://forums.phpfreaks.com/topic/33811-listsdatabase-favourite-system-help/
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?
[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?
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.