SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get value from other table and show its label

    Hi, sorry if this is not the proper forum to post this.

    Look, i have php page that lists a bunch of records. This records are store in a table named "lyrics" that has three fields: title, lyrics and id_author (it's a foreing key). Now, on the other hand, i have other table named "authors" and it containes two fields: id_author and author_name, ok?

    I already create a "master page" that lists all lyrics and a "detail page" and they are working just fine.

    What i want to do and don't know how, is that on each detail lyric page i want to put the author's name. I put the id_author from the "author" table and of course it shows me the id_author, but i need the NAME of the author.

    See my point?, there should be a way to create a relationship between the id_author from the "author" table and the id_author from the "lyrics" table and this relationship should give me the "author_name" value, not the "id_author" value.

    Ok, i hpe i made my self clear, let me know if someone know how to solve this.

    Many thanks to all of you.

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like this is the wrong forum, most likely the better forum would be the database one?

    On the otherhand, if you want some help, could you post the schema?

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Shorewood, IL
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look at this and let me know if this is something like you are looking for.

    Cake Scaffold and Table Joins

    Click on the Edit links.

    Code is not completed for all methods, but will be added soon.
    /**
    * @author Larry E. Masters aka PhpNut
    * @url CakePHP Rapid Development Framework
    */

  4. #4
    SitePoint Member
    Join Date
    May 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about posting here. I'm moving this to the appropiate forum.
    1PhpNut, that's not what i'm trying to do, but thanks anyway.
    See you.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Shorewood, IL
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are wanting to create a join correct?
    You need something like this.
    Code:
    SELECT * FROM lyrics LEFT JOIN author ON lyrics.id_author = author.id_author;
    That should return the author name also
    But without seeing your tables I can not tell for sure

    Then you would use author_name instead of id_author your code.
    /**
    * @author Larry E. Masters aka PhpNut
    * @url CakePHP Rapid Development Framework
    */

  6. #6
    SitePoint Member
    Join Date
    May 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's right 1PhpNut, i think your query is the way to go. Thank you very much.


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
  •