Jump to content


Photo

what is the best approach?


  • Please log in to reply
2 replies to this topic

#1 n8w

n8w
  • Members
  • PipPipPip
  • Advanced Member
  • 123 posts

Posted 26 February 2006 - 03:30 PM

I am creating a "my favorites" 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--]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.[!--sizec--][/span][!--/sizec--]


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




#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 26 February 2006 - 08:15 PM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 n8w

n8w
  • Members
  • PipPipPip
  • Advanced Member
  • 123 posts

Posted 27 February 2006 - 02:12 AM

Hey Fenway .. thanks for responding. I think I will try the Iframe approach.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users