First PHP/MySQL Project Day 6: Joining Tables Together

For the last video in this series, I learned how to join two tables together with cross joins, inner joins, and outer joins. Exciting stuff here! (And I don’t mean that sarcastically. Learning about joins opens up a whole new world of database possibilities!) Anyway, this video is five and a half minutes long. Enjoy!

Links for Joining Tables Together

These sites are chock-full of information. If you just want to review the basics, the first link is all you need:

  • SQL Join - From W3Schools, some examples and explanations of inner joins and outer (left and right) joins.
  • Join Syntax - Everything you ever wanted to know about MySQL’s join syntax, directly from the MySQL manual.
  • Join (SQL) - From Wikipedia, lots of details on many types of joins.

So now that I’ve learned how use joins, I think it’s safe to say I’ve covered the basics of MySQL! I’m hoping this is the first of many milestones. And who knows? Maybe once I learn more advanced stuff, I’ll come back to this project and turn it into something useful.

Posted on August 11th, 2007 | Leave a comment | Trackback URL

5 Comments

  1. Yas

    August 12th, 2007

    Cool! :)

    You should take a look at PHP Object Oriented Programming. It is better then doing it the other way because you don’t have to write as much code, well for big projects anyway.

    I’ve been messing about with css, here take a look. Not anything that I would use for a website, except maybe the dark layout, 4.

    http://yaseen.iifree.net/1/index.html
    http://yaseen.iifree.net/2/index.html
    http://yaseen.iifree.net/3/index.html
    http://yaseen.iifree.net/4/index.html

    Still making some more. :)

  2. Riihele

    August 12th, 2007

    Hei Liz.

    BRILLIANT!
    Have been trying to crack the codes on these things myself for a good while, so the links are very useful to me indeed.
    Continued Grand Day to you and yours.

  3. LearningNerd

    August 14th, 2007

    Thanks, guys!

    Yas - Nice job on those layouts! I should follow your example and practice my CSS too, lol. And of course the Object Oriented Programming… One more thing on my list!

  4. Simon

    July 30th, 2008

    Excellent tutorial.

    I found this while searching for an example of a php/mysql database as I want to write a simple (very very simple!) help desk application ( I help out at some schools and want the teachers to have a simple way of recording requests/faults).

    Would it be possible, please, to have a copy of the code used in the final tutorial to use as a starting point (to save some typing :) )
    regards
    Simon

  5. LearningNerd

    July 30th, 2008

    Hi, Simon, and thanks! I lost my copy of the the code I used in this series but I typed up what was shown in this last video. It’s just part of what’s required to make everything work, though… this doesn’t include connecting to MySQL, or the rest of the form(s) shown. But hopefully this excerpt is better than nothing.

    (By the way, check out a forum like PHP Freaks for help.)


    // Selecting the data

    $resultselect = mysqlquery(’SELECT id, item, todo.tag, deadline, color FROM todo LEFT JOIN tags ON todo.tag = tags.tag’);

    // Fetching and displaying the data
    while($row = mysql_fetch_array($resultselect)) { ?>

    <?php if($row[’color’]) { ?>
    <span stlye=”color:<?php echo $row[’color’] ?>”>
    <?php } ?>

    <input type=”checkbox” name=”done[]”
      id=”<?php echo $row[’id’] ?>”
      value=”<?php echo $row[’id’] ?>” />

    <label for=”<?php echo $row[’id’] ?>”>

    <?php echo $row[’item’];

    if($row[’tag’]) {
      echo ‘ - tagged ‘ . $row[’tag’]; }

    if($row[’deadline’] != 0000-00-00) {
      echo ‘ - due on ‘ . $row[’deadline’]; }

    ?>

    </label>

    <?php if($row[’color’]) { ?>
      </span>

    <?php }

    } ?>

Share Your Thoughts