SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    displaying item in favourite list

    i have save user's favourite posting in to database..

    the record is saved in the format "1,3, 15"

    when user adding a new posting id (eg.10) to the favourite list,the record become "10, 1,3, 15"

    i'm having problemin displaying the favourite list of the user.

    how can i display the item in the below format?

    id:10
    title:
    author:

    id:1
    title:
    author:

    id:3
    title:
    author:

    .
    .
    .
    .

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,248
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    it is very, very difficult to join one table with titles and authors repetitively to another table with a column that contains a comma-delimited list of ids in a single value

    do a search for normalization and another search for many-to-many relationships

    you should redesign the tables now before you go much further
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is there any easier and effective way to store the item to the favourite list?

    shall i create a table which contains member id and favourite item, and each time the user add a new favourite, a new record will be created?

    thank you, r937!

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cathie View Post
    shall i create a table which contains member id and favourite item, and each time the user add a new favourite, a new record will be created?)
    yes.
    Code:
    create table favorites (
       member_id int unsigned
     , post_id int unsigned
     , primary key (member_id, post_id)
    )

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by longneck View Post
    yes.
    Code:
    create table favorites (
       member_id int unsigned
     , post_id int unsigned
     , primary key (member_id, post_id)
    )
    thank you, longneck!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •