Professional Web Applications Themes

[PHP] discussion forum from j. meloni's book - PHP Development

> > // the query > > $verify = "select ft.topic_id, ft.topic_title from forum_posts as fp left > join forum_topics as ft on fp.topic_id = ft.topic_id where fp.post_id = > $_GET[post_id]"; > ........................... > > My question: why - or how can - the columns ft.topic_id and ft.topic_title > come from the table forum_posts? > > In the original schema, there is no column called topic_title in the table > called forum_posts. They don't. ft is aliased to forum_topics....

  1. #1

    Default RE: [PHP] discussion forum from j. meloni's book

    >
    > // the query
    >
    > $verify = "select ft.topic_id, ft.topic_title from forum_posts as fp left
    > join forum_topics as ft on fp.topic_id = ft.topic_id where fp.post_id =
    > $_GET[post_id]";
    > ...........................
    >
    > My question: why - or how can - the columns ft.topic_id and ft.topic_title
    > come from the table forum_posts?
    >
    > In the original schema, there is no column called topic_title in the table
    > called forum_posts.
    They don't. ft is aliased to forum_topics.

    Jennifer Goodie Guest

  2. #2

    Default Re: [PHP] discussion forum from j. meloni's book

    Jennifer Goodie" <goodieapollointeractive.com> writes:
    They don't. ft is aliased to forum_topics.
    .........................

    That's right.

    ft is aliased to the forum_topics table.

    The query reads:
    ............
    $verify = "select ft.topic_id, ft.topic_title from forum_posts as fp left
    join forum_topics as ft on fp.topic_id = ft.topic_id where fp.post_id =
    $_GET[post_id]";
    ..............
    The question:

    How can the column that is called:
    ft.topic_title

    in the select statement above

    be taken from the table called forum_posts when it was not there in the
    schema?

    "SELECT ft.topic_id, ft.topic_title FROM forum_posts...[snipped]

    Thank you.
    TR

    ---
    [This E-mail scanned for viruses by gonefishingguideservice.com]

    Anthony Ritter Guest

  3. #3

    Default RE: [PHP] discussion forum from j. meloni's book

    > -----Original Message-----
    > From: Anthony Ritter [mailto:tonygonefishingguideservice.com]
    > Sent: 13 August 2003 02:57
    >
    > Jennifer Goodie" <goodieapollointeractive.com> writes:
    >
    > > You didn't switch the aliases around, you just switched the
    > join order.
    > > This will provide unexpected results. In order to
    > understand it, you
    > should
    > > read up on left joins.
    > > [url]http://www.mysql.com/doc/en/JOIN.html[/url]
    > ............................
    > Thank you. But...
    >
    > // the query
    >
    > $verify = "select ft.topic_id, ft.topic_title from
    > forum_posts as fp left
    > join forum_topics as ft on fp.topic_id = ft.topic_id where
    > fp.post_id =
    > $_GET[post_id]";
    > ...........................
    >
    > My question: why - or how can - the columns ft.topic_id and
    > ft.topic_title
    > come from the table forum_posts?
    You have a conceptual misconception. In effect, you need to read that query
    as:

    "select ft.topic_id, ft.topic_title
    from ( forum_posts as fp
    left join forum_topics as ft
    on fp.topic_id = ft.topic_id
    )
    where fp.post_id = $_GET[post_id]"

    In other words, the left join of the two tables is treated as a single
    virtual table, from which you could select any column of either original
    table.

    Cheers!

    Mike

    ---------------------------------------------------------------------
    Mike Ford, Electronic Information Services Adviser,
    Learning Support Services, Learning & Information Services,
    JG125, James Graham Building, Leeds Metropolitan University,
    Beckett Park, LEEDS, LS6 3QS, United Kingdom
    Email: [email]m.fordlmu.ac.uk[/email]
    Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
    Mike Ford Guest

  4. #4

    Default Re: [PHP] discussion forum from j. meloni's book

    Ford, Mike [LSS]" <M.Fordlmu.ac.uk> writes:
    > You have a conceptual misconception. In effect, you need to read that
    query
    > as:
    >
    > "select ft.topic_id, ft.topic_title
    > from ( forum_posts as fp
    > left join forum_topics as ft
    > on fp.topic_id = ft.topic_id
    > )
    > where fp.post_id = $_GET[post_id]"
    >
    > In other words, the left join of the two tables is treated as a single
    > virtual table, from which you could select any column of either original
    > table.
    ...................

    Thanks Mike for the clear explanation.

    TR



    ---
    [This E-mail scanned for viruses by gonefishingguideservice.com]

    Anthony Ritter Guest

  5. #5

    Default Re: [PHP] discussion forum from j. meloni's book

    Ford, Mike [LSS]" <M.Fordlmu.ac.uk> writes:
    > You have a conceptual misconception. In effect, you need to read that
    query
    > as:
    >
    > "select ft.topic_id, ft.topic_title
    > from ( forum_posts as fp
    > left join forum_topics as ft
    > on fp.topic_id = ft.topic_id
    > )
    > where fp.post_id = $_GET[post_id]"
    >
    > In other words, the left join of the two tables is treated as a single
    > virtual table, from which you could select any column of either original
    > table.
    ...................

    Thanks Mike for the clear explanation.

    TR





    Anthony Ritter Guest

Similar Threads

  1. Discussion Forum
    By Bobbie in forum Coldfusion Database Access
    Replies: 5
    Last Post: June 3rd, 04:02 PM
  2. Hosting a Discussion Forum
    By GreatPaulC in forum Macromedia Dynamic HTML
    Replies: 6
    Last Post: November 6th, 11:31 AM
  3. discussion forum from j. meloni's book
    By Anthony Ritter in forum PHP Development
    Replies: 3
    Last Post: August 13th, 04:53 AM
  4. discussion forum using dreamweaver mx
    By jonnyfriendly webforumsuser@macromedia.com in forum Macromedia Dreamweaver
    Replies: 7
    Last Post: July 26th, 08:19 AM
  5. discussion forum design
    By hj in forum PHP Development
    Replies: 3
    Last Post: July 25th, 07:25 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139