SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Addict isuru's Avatar
    Join Date
    Nov 2000
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am making a PHP/MySQL message board but I need a little help.
    I want to be able to display the author of a post.
    I have one table for topics and another for members.
    The problem is that in the topics table the author's ID is stored and not the members username. This ID corresponds with the ID in the members table.

    I know I can use an SQL statement like:
    SELECT UserName from members WHERE members.UserName = topics.Author

    But the thing is that I am already executing other SQL statements to get other details of the topic

    So I gues what I a m asking is how do I use the above SQL satement within another SQL statement?

  2. #2
    SitePoint Addict isuru's Avatar
    Join Date
    Nov 2000
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Somebody PLEASE HELP, Im DESPERATE

  3. #3
    Freelance Web Designer KeithMcL's Avatar
    Join Date
    Oct 1999
    Location
    Dublin, Ireland
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd suggest visiting http://www.hotscripts.com/PHP/Tips_a...ussion_Boards/ for some tutorials.

    (P.S I'd love to know how many times i've told people to go to hotscripts.com )

  4. #4
    SitePoint Addict isuru's Avatar
    Join Date
    Nov 2000
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately that doesn't really help me because they are just tutorials. I need help with the specific example

  5. #5
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I might be able to help, but I dont see why you would ever need a SQL statement inside anohter one...could you descirbe better please...

  6. #6
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to fetch details of the topic at the same time as you fetch the author e.g.

    SELECT topic.*, members.UserName FROM topic, members WHERE members.UserId=topic.Author

    That query should fetch all the info about a topic and the username of the author for you.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  7. #7
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a questoin...

    if you have your sql statement and it goes something like this

    SELECT topic.name, author.name FROM topics, authors WHERE topic.id=$id AND topic.aid=author.aid;

    then you do $result=mysql_fetch_array($sql);

    how do you access author.name?

    $result[name] is the one that came first, and thats topic.name. but whered author.name go?

    also, i just thought of these two things. one, why is it WHERE topic.aid=author.aid instead of WHERE topic.aid==author.aid?

    and, why do you say WHERE bla blah AND bla bla instead of WHERE bla bla, bla bla?

    thanks.


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
  •