This is a tough one for me to get my head around, wonder if anyone can help.
I'm calling results from two tables in the same database.
One table is called 'castcrew' which has the prog_id of a particlar tv programme in my database (from another table called 'progs')and then the fields director1, director2, producer1, producer2 etc. in these fields there is an id number of a person. that relates to another table i have 'people' which includes their name, dob, pob etc.
I want a page to display all the programmes, they have produced and/or directed. But if they have directed two programmes it will only display one of the programmes they have directed.
Here's my code - may be a bit slapdash cos i am a relative begginner..
function showdirectoredprogrammes($people_id){
$query = "SELECT * FROM castcrew WHERE director = '$people_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames');
$num = mysql_num_rows($result);
while ( $rows = mysql_fetch_array($result) ) {
$prog_id = $rows['prog_id'];
$query = "SELECT * FROM progs WHERE prog_id = '$prog_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames2');
while ( $rows = mysql_fetch_array($result) ) {
$title = $rows['title'];
$first_shown = $rows['first_shown'];
$prog_id = $rows['prog_id'];
$channel = $channel['channel'];
echo("<a href=\"../show.php?prog_id=$prog_id\">$title</a> ($first_shown)<br>");
} // ends while loop
}
$query = "SELECT * FROM castcrew WHERE director1 = '$people_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames');
$num = mysql_num_rows($result);
while ( $rows = mysql_fetch_array($result) ) {
$prog_id = $rows['prog_id'];
$query = "SELECT * FROM progs WHERE prog_id = '$prog_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames2');
while ( $rows = mysql_fetch_array($result) ) {
$title = $rows['title'];
$first_shown = $rows['first_shown'];
$prog_id = $rows['prog_id'];
$channel = $channel['channel'];
echo("<a href=\"../show.php?prog_id=$prog_id\">$title</a> ($first_shown)<br>");
} // ends while loop
}
$query = "SELECT * FROM castcrew WHERE director2 = '$people_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames');
$num = mysql_num_rows($result);
while ( $rows = mysql_fetch_array($result) ) {
$prog_id = $rows['prog_id'];
$query = "SELECT * FROM progs WHERE prog_id = '$prog_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames2');
while ( $rows = mysql_fetch_array($result) ) {
$title = $rows['title'];
$first_shown = $rows['first_shown'];
$prog_id = $rows['prog_id'];
$channel = $channel['channel'];
echo("<a href=\"../show.php?prog_id=$prog_id\">$title</a> ($first_shown)<br>");
} // ends while loop
}
$query = "SELECT * FROM castcrew WHERE director3 = '$people_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames');
$num = mysql_num_rows($result);
while ( $rows = mysql_fetch_array($result) ) {
$prog_id = $rows['prog_id'];
$query = "SELECT * FROM progs WHERE prog_id = '$prog_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames2');
while ( $rows = mysql_fetch_array($result) ) {
$title = $rows['title'];
$first_shown = $rows['first_shown'];
$prog_id = $rows['prog_id'];
$channel = $channel['channel'];
echo("<a href=\"../show.php?prog_id=$prog_id\">$title</a> ($first_shown)<br>");
} // ends while loop
}
$query = "SELECT * FROM castcrew WHERE director4 = '$people_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames');
$num = mysql_num_rows($result);
while ( $rows = mysql_fetch_array($result) ) {
$prog_id = $rows['prog_id'];
$query = "SELECT * FROM progs WHERE prog_id = '$prog_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames2');
while ( $rows = mysql_fetch_array($result) ) {
$title = $rows['title'];
$first_shown = $rows['first_shown'];
$prog_id = $rows['prog_id'];
$channel = $channel['channel'];
echo("<a href=\"../show.php?prog_id=$prog_id\">$title</a> ($first_shown)<br>");
} // ends while loop
}
$query = "SELECT * FROM castcrew WHERE director5 = '$people_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames');
$num = mysql_num_rows($result);
while ( $rows = mysql_fetch_array($result) ) {
$prog_id = $rows['prog_id'];
$query = "SELECT * FROM progs WHERE prog_id = '$prog_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames2');
while ( $rows = mysql_fetch_array($result) ) {
$title = $rows['title'];
$first_shown = $rows['first_shown'];
$prog_id = $rows['prog_id'];
$channel = $channel['channel'];
echo("<a href=\"../show.php?prog_id=$prog_id\">$title</a> ($first_shown)<br>");
} // ends while loop
}
$query = "SELECT * FROM castcrew WHERE director6 = '$people_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames');
$num = mysql_num_rows($result);
while ( $rows = mysql_fetch_array($result) ) {
$prog_id = $rows['prog_id'];
$query = "SELECT * FROM progs WHERE prog_id = '$prog_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames2');
while ( $rows = mysql_fetch_array($result) ) {
$title = $rows['title'];
$first_shown = $rows['first_shown'];
$prog_id = $rows['prog_id'];
$channel = $channel['channel'];
echo("<a href=\"../show.php?prog_id=$prog_id\">$title</a> ($first_shown)<br>");
} // ends while loop
}
$query = "SELECT * FROM castcrew WHERE director7 = '$people_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames');
$num = mysql_num_rows($result);
while ( $rows = mysql_fetch_array($result) ) {
$prog_id = $rows['prog_id'];
$query = "SELECT * FROM progs WHERE prog_id = '$prog_id'";
$result = mysql_query($query) or die ('Unable to query database for peoplenames2');
while ( $rows = mysql_fetch_array($result) ) {
$title = $rows['title'];
$first_shown = $rows['first_shown'];
$prog_id = $rows['prog_id'];
$channel = $channel['channel'];
echo("<a href=\"../show.php?prog_id=$prog_id\">$title</a> ($first_shown)<br>");
} // ends while loop
}
} //ends function