Re: Clarity needed

From: Date: Wed, 04 Feb 2009 22:43:22 +0000
Subject: Re: Clarity needed
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-287664@lists.php.net to get a copy of this message
On Wed, Feb 4, 2009 at 17:24, tedd <tedd@sperling.com> wrote: [snip!] > > I understand that I can have one record set up for each tutor, and another > record set up for each course, and then tie the two together by another > record like an assignment. That way I can have as many assignments as I want > tying courses to tutors. > > It that the way you guys would do it? I would, yes. Very basically: database.tutors: id INT(8) NOT NULL auto_increment f_name VARCHAR(32) l_name VARCHAR(32) database.courses id INT(8) NOT NULL auto_increment class_name VARCHAR(90) class_description MEDIUMTEXT database.course_tutors id INT(8) NOT NULL auto_increment tutor_id INT(8) course_id INT(8) Then just run the query you want based on the following example: <?php // Database includes, etc.... $sql = "SELECT course_name,course_description FROM courses WHERE id "; $sql .= "IN (SELECT course_id FROM course_tutors WHERE tutor_id="; $sql .= "'".mysql_real_escape_string($_GET['tutor_id'])."')"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo "Class: ".$row['course_name']."<br />\n"; echo "Description: ".$row['course_description']."<br />\n"; } ?> You can also use JOINs and so forth, of course, but a simple WHERE/IN should be fine. -- </Daniel P. Brown> daniel.brown@parasane.net || danbrown@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Unadvertised dedicated server deals, too low to print - email me to find out!

« previous php.general (#287664) next »