Jump to content

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
n8w

Should I write a few sql statements


Link to comment
https://forums.phpfreaks.com/topic/3627-what-is-the-best-approach/
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.
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.