Use of Multiple tables in query

I am still somewhat new at this stuff, been able to modify code to my likings, but am starting to write my own script for my schedules. I am having difficulty trying to build a relationship with different tables.

CREATE TABLE f2007_divisions (
division_id int(5) unsigned NOT NULL auto_increment,
age text NOT NULL,
division text NOT NULL,
PRIMARY KEY (division_id)

CREATE TABLE f2007_scheduling (
club_id smallint(3) NOT NULL default ‘0’,
status text NOT NULL,
division_id int(5) NOT NULL default ‘0’,
game_id int(6) unsigned NOT NULL auto_increment,
date date NOT NULL default ‘0000-00-00’,
notes text NOT NULL,
time time NOT NULL default ‘00:00:00’,
home_team varchar(50) NOT NULL default ‘’,
h_score text NOT NULL,
field text NOT NULL,
field_no text NOT NULL,
visit_team varchar(50) NOT NULL default ‘’,
v_score text NOT NULL,
sched_user smallint(5) unsigned NOT NULL default ‘0’,
PRIMARY KEY (game_id),
KEY division_id (division_id),

How do I build the relationship so that when I write:


// mySQL Table
$division_id = $_GET[‘division_id’];
$sql = “SELECT * FROM f2007_scheduling WHERE division=’$division_id’ ORDER BY date ASC”;
$result = mysql_query($sql) or die(mysql_error());
$i = 0;

echo "

n"; while ($data = dbarray($sql)) { $i % 2 == 0 ? $tclass='tbl1' : $tclass='tbl2';
	echo "<tr>
	<td class='$tclass'><font size='1'>".$data['div']."</font></td>
	<td class='$tclass'><font size='1'>".$data['game_id']."</font></td>
	<td class='$tclass'><font size='1'>".$data['date']=date("D, M j, Y",strtotime($data['date']))."</font></td>
	<td class='$tclass'>
	<p style='margin-top: 0; margin-bottom: 0'><font size='1'>".$data['time']."</font></p></td>
	<td class='$tclass'><p style='margin-top: 0; margin-bottom: 0'><font size='1'>".$data['home_team']." 



n"; } echo "
Division: Game ID: Date: True Time: Teams: Field:
“.$data[‘field’].” “.$data[‘field_no’].”
?>[/code] I can have "division" from f2007_division table display in place of ".$data['div']."?

is ur code realy working? in ur mysql-dump there is no field called division.
and i have no idea where $data[‘div’] is coming from. as there is no field called div as well.

u can select data from multible tables:
SELECT f2007_scheduling.*,f2007_divison.division FROM f2007_scheduling,f2007_divison WHERE f2007_scheduling.division_id=’$division_id’ AND f2007_scheduling.division_id=f2007_divison.division_id ORDER BY date ASC

and then use $data[‘division’] i guess. if i my guess that dbarray($sql) is suposed to return the result on mysql_fetch_assoc() is right.

The code structure was from last season and worked fine. I missed updating the code, since I changed field names, obviously. div now became division_id to reflect the new tables and hopefully efficiency.

Sponsor our Newsletter | Privacy Policy | Terms of Service