PHP/MySQL Left Join Question

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default Re: PHP/MySQL Left Join Question

    CM: Finally getting back to this and maybe being in the middle of a bad flu
    ain't helping, but I'm not getting the names to print and am wondering whether
    I'm not using the right nomenclature in the table. My select statement (w/only
    slight variation to yours) is:

    $query_datetest = "SELECT DATE_FORMAT(alumni.last_modified, '%m/%d/%Y') as
    lastDate, alumni.alumni_id, alumni.firstName, alumni.nickName, ...,
    t1.lastName, t2.lastName, t3.lastName, t4.lastName FROM alumni LEFT OUTER JOIN
    thesis_committee t1 ON alumni.committeeChair = t1.committee_id LEFT OUTER JOIN
    thesis_committee t2 ON alumni.committee2 = t2.committee_id LEFT OUTER JOIN
    thesis_committee t3 ON alumni.committee3 = t3.committee_id LEFT OUTER JOIN
    thesis_committee t4 ON alumni.committee4 = t4.committee_id ORDER BY
    alumni.lastName";

    But I'm assuming that I need to modify how I invoke the printout from what I
    have below:

    <td><p><?php echo $row_datetest['thesisComm']; ?></p></td>
    <td><p><?php echo $row_datetest['committee2']; ?></p></td>
    <td><p><?php echo $row_datetest['committee3']; ?></p></td>
    <td><p><?php echo $row_datetest['committee4']; ?></p></td>

    No? I tried naming the <td> fields t1.lastName, etc., and as you likely would
    know, that didn't work. I'm hoping there's an obvious oversight. Thanks for any
    help you can provide.

    mduke Guest

  2. Similar Questions and Discussions

    1. Is left-join faster then inner join?
      Some people said that using left-join is generally faster than inner join, is that true? Thanks...
    2. Left join isn't joining
      Hello, I've got a select statement that joins two tables. -- tblPageHitCalendar contains a single column holding dates. It has every day since...
    3. Left join, grouped output question
      Hey All, I have a SQL JOIN / Output question. So for this simple CMS I have built I two tables I am joinging. An "issues" table (as in magazine...
    4. MySQL Left Join Question
      This may not be the best place to ask this question, but I'm running into a problem when I perform a left join sql statement in PHP. The sql...
    5. left join problem
      if you just need something unique in the result set, 1. combination (NJIDATA.GLPMSTR.ID, NJIDATA.GLPMTRN.ID) is unique 2. you could also use...
  3. #2

    Default Re: PHP/MySQL Left Join Question

    You're almost there. You need to give each column with the same column name
    an alias, as table names are no longer available when you've retrieved the
    records.

    SELECT ...snip..., t1.lastName AS Chairman, t2.lastName AS Member1,
    t3.lastName AS Member2, t4.lastName AS Member3, ...snip...

    Then, change your table to call the fields with those aliases:
    <td><p><?php echo $row_datetest["Chairman"]; ?></p></td>
    <td><p><?php echo $row_datetest["Member1"]; ?></p></td>
    <td><p><?php echo $row_datetest["Member2"]; ?></p></td>
    <td><p><?php echo $row_datetest["Member3"]; ?></p></td>

    That's the final step. :)

    "mduke" <webforumsuser@macromedia.com> wrote in message
    news:cvo31u$ln0$1@forums.macromedia.com...
    > CM: Finally getting back to this and maybe being in the middle of a bad
    flu
    > ain't helping, but I'm not getting the names to print and am wondering
    whether
    > I'm not using the right nomenclature in the table. My select statement
    (w/only
    > slight variation to yours) is:
    >
    > $query_datetest = "SELECT DATE_FORMAT(alumni.last_modified, '%m/%d/%Y')
    as
    > lastDate, alumni.alumni_id, alumni.firstName, alumni.nickName, ...,
    > t1.lastName, t2.lastName, t3.lastName, t4.lastName FROM alumni LEFT OUTER
    JOIN
    > thesis_committee t1 ON alumni.committeeChair = t1.committee_id LEFT OUTER
    JOIN
    > thesis_committee t2 ON alumni.committee2 = t2.committee_id LEFT OUTER JOIN
    > thesis_committee t3 ON alumni.committee3 = t3.committee_id LEFT OUTER JOIN
    > thesis_committee t4 ON alumni.committee4 = t4.committee_id ORDER BY
    > alumni.lastName";
    >
    > But I'm assuming that I need to modify how I invoke the printout from
    what I
    > have below:
    >
    > <td><p><?php echo $row_datetest['thesisComm']; ?></p></td>
    > <td><p><?php echo $row_datetest['committee2']; ?></p></td>
    > <td><p><?php echo $row_datetest['committee3']; ?></p></td>
    > <td><p><?php echo $row_datetest['committee4']; ?></p></td>
    >
    > No? I tried naming the <td> fields t1.lastName, etc., and as you likely
    would
    > know, that didn't work. I'm hoping there's an obvious oversight. Thanks
    for any
    > help you can provide.
    >

    CMBergin Guest

  4. #3

    Default Re: PHP/MySQL Left Join Question

    Hallelujah, that worked! Well, at least I was somewhat on the right track in
    assuming I had to invoke the table output differently--just left out the other
    "shoe" to that, obviously.

    Thanks very much for your patience and assistance. Now I can leave work early
    and try to recuperate from this rotten flu!

    mduke Guest

  5. #4

    Default Re: PHP/MySQL Left Join Question

    No problem. :)
    Hope you feel better.

    "mduke" <webforumsuser@macromedia.com> wrote in message
    news:cvo7s8$s5n$1@forums.macromedia.com...
    > Hallelujah, that worked! Well, at least I was somewhat on the right track
    in
    > assuming I had to invoke the table output differently--just left out the
    other
    > "shoe" to that, obviously.
    >
    > Thanks very much for your patience and assistance. Now I can leave work
    early
    > and try to recuperate from this rotten flu!
    >

    CMBergin Guest

Posting Permissions

  • You may not post new threads
  • You may 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