Jump to content

Creating Query where two variables from two tables match


slaterino

Recommended Posts

Hi,

I am trying to create a query where 'cl_course' in the 'classes' table is simply an ID number for a course. In a seperate table, 'courses' I have a corresponding ID number, called 'cou_ID' in this table, as well as a 'cou_name' field which is the name of the course.

 

I am therefore trying to create a query where it lists all the entries from the 'classes' table but replaces the 'cl_course' field with 'cou_name' from the 'courses' table. I have come up with a query which almost works, but lists an entry for every course as well as every class, when it should just be for every class. This is the coding I have at the moment. I have tried a number of things but can't work out where I would add some sort of class stating that 'cl_course' equals 'cou_ID'.

 

<?php

        $result = mysql_query("SELECT * FROM classes, courses ORDER BY cl_date", $conn);
        while($myrow = mysql_fetch_array($result))
             {
               echo "<tr><td><b>";
               echo $myrow['cou_name'];
               echo "</b></td><td> ";
               echo $myrow['cl_date'];
               echo "</td><td><a href=\"edit.php?cl_ID=" . $myrow['cl_ID'] . "\">Edit</a> | <a href=\"delete.php?cl_ID=" . $myrow['cl_ID'] . "\">Delete</a></td></tr><br />";             }
?>

 

Thanks

Russ

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.