Jump to content


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


what is the best approach?

Recommended Posts

I am creating a [b]"my favorites" [/b]feature on [a href=\"http://www.illustrationmundo.com/illustrators.php?str_date=rb\" target=\"_blank\"]http://www.illustrationmundo.com/illustrat...php?str_date=rb[/a] where when a user is logged in they can add the illustrators they like to their favorites list

The favorites table will have the following fields:

user_id - login id
illustrator_id - the id of the illustrator they want to save as one fo their favorites
date - current date

So I have two questions

[!--sizeo:2--][span style=\"font-size:10pt;line-height:100%\"][!--/sizeo--][b]1. When a user clicks "add favorite" should I have this as an ajax function that processes this request and updates the page without changing the page (if so how do I do this .. or go about learning how to do this).. if not .. I assume I just have a php page that will process this info and return the user back to the page they were previously on.[/b][!--sizec--][/span][!--/sizec--]

[!--sizeo:2--][span style=\"font-size:10pt;line-height:100%\"][!--/sizeo--][b]2. What is the best way to write the sql statement to insert/update this in the database?[/b][!--sizec--][/span][!--/sizec--]

In the past I have wrote multiple SQL statements .. with a series of "if" statements .. but I am sure there is a more effecient way to do this??

What I have been doing is ...

if the table has user_id and artist_id as the primary key
then write a sql statement that UPDATES the table
if not
write a sql statement thatn inserts this info

is there an easy way where you can just write .. insert this info .. and if it exists it overwrites it .. or do you have to do it the way I have been doing it?

Thanks so much

Should I write a few sql statements

Share this post

Link to post
Share on other sites
Well, you could always go the AJAX route (or the preferred IFRAME route, IMHO); alternatively, just have an "Add" button to add another favourite, and then a "Save" button that calls the desired php script. Depending on the table layout, you could always use a REPLACE INTO, assuming you don't care about the UIDs.

Share this post

Link to post
Share on other sites
Hey Fenway .. thanks for responding. I think I will try the Iframe approach.

Share this post

Link to post
Share on other sites


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.