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.



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.
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.
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!
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
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 }
} ?>
August 21st, 2008
It explained what exactly I wanted to know!
Thanks to LearningNerd team.
September 16th, 2008
Hi Team,
I am using the same syntax for my database but its showing me the ids(int) of another table instead of strings(varchar).
I am using MyISAM engine.
Does the engine affect joining two tables?
Here is my code:
$sql = “SELECT * FROM (org LEFT JOIN category ON org.org_category = category.category_id) ORDER BY org.org_id DESC”;
What was going wrong?
Thanks in advance!