Mutley Posted January 11, 2007 Share Posted January 11, 2007 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:article1article8article11article12in 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. :) Quote Link to comment Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 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 Link to comment Share on other sites More sharing options...
Eddyon Posted January 11, 2007 Share Posted January 11, 2007 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 Link to comment Share on other sites More sharing options...
Mutley Posted January 11, 2007 Author Share Posted January 11, 2007 [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? Quote Link to comment Share on other sites More sharing options...
Eddyon Posted January 11, 2007 Share Posted January 11, 2007 Yep, just insert the username and the favourite as a new record. Quote Link to comment Share on other sites More sharing options...
Eddyon Posted January 11, 2007 Share Posted January 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.