Hi Guys
I have two tables I'm trying to pull information from. In the end I want to be able to display a username and a school name which are contained in 2 separate tables but linked by the school id number. The problem is that the 'members' table which holds most of the information like the username etc, only contains a school 'id' number while the actual school name is contained in a 'high_schools table' with the actual names. How do I join(or do anything else) that will allow me to display the actual school name and not just the school id number? So that in the end I have the following:
john2005 - Aladin High School
and not just:
john2005 - 57
Below is the code for the two tables and the php script I'm developing to populate the page/report.
Thanks in advance.
MEMBERS TABLE
CREATE TABLE `members` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(15) NOT NULL default '',
`password` varchar(15) NOT NULL default '',
`email` varchar(125) NOT NULL default '',
`first_name` varchar(125) NOT NULL default '',
`last_name` varchar(75) NOT NULL default '',
`high_school_attended` int(11) NOT NULL default '0',
`graduation_year` int(11) NOT NULL default '0',
`date_of_birth` date NOT NULL default '0000-00-00',
`comments` text NOT NULL,
`status` smallint(6) NOT NULL default '1',
`date_added` date NOT NULL default '0000-00-00',
`last_modified` date default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=3448 ;
HIGH SCHOOLS TABLE
CREATE TABLE `high_schools` (
`id` int(11) NOT NULL auto_increment,
`high_school` varchar(125) NOT NULL default '',
`status` smallint(6) NOT NULL default '1',
`date_added` date NOT NULL default '0000-00-00',
`last_modified` date default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1343 ;
<?php
$dbhost = "localhost";
$dbuser = "php";
$dbpwd = "hello";
$dbname = "jokes";
$conn = mysql_connect($dbhost, $dbuser, $dbpwd ) or die(mysql_error());
mysql_select_db($dbname, $conn) or die(mysql_error());
echo "DB Connected<BR>";
$query = "SELECT * from members";
$result = mysql_query($query, $conn);
for ($i = 0; $i < mysql_num_rows($result) ; $i++ ){
$username = mysql_result($result, $i, "username");
$school = mysql_result($result, $i, "high_school_attended");
print "$username - ";
print "$school<BR>";
}
?>