Hello all,
I think nested loops will do what I want, but I can't seem to get them
right.
I have two tables, members and casts. I run a query as follows:
$sql_query="SEL ECT DISTINCT casts.yearID, members.memberN ame"
. " FROM members INNER JOIN casts ON members.memberI D =
casts.memberID"
. " WHERE (((casts.yearID ) In (SELECT DISTINCT yearID FROM
casts WHERE memberID='$id') ) AND ((casts.memberI D)<>'$id'));";
Which gets me the data I want to display using the following php:
$result=mysql_q uery($sql_query );
$num=mysql_numr ows($result);
echo "Cast data for: <b>$castmembe r</b>"; ID:$id<br>";
$year =mysql_result($ result,$i,"year ID");
echo " 1st season: <b>$year</b><p>";
//set up table for $result
print "<table width=200 border=0>\n";
print "\t<td><fon t face=arial size=1/><b>Cast Member</font></td>\n";
print "\t<td><fon t face=arial size=1/><b>Season</font></b></td>\n";
//loop through $result
$i=0;
while ($i < $num) {
$member=mysql_r esult($result,$ i,"memberName") ;
$year =mysql_result($ result,$i,"year ID");
print "<tr>\n";
print "\t<td><fon t face=arial size=1/>$member</font></td>\n";
print "\t<td><fon t face=arial size=1/>$year</font></td>\n";
print "</tr>\n";
$i++;
}
print "</table>\n";
?>
<?php echo "Cast data for: <b>",$castmembe r; ?><br></b>
However, the data is just one long list in the table with the two
columns Cast Member and Season. What I want to do is have a separate
table for each Season so that when yearID changes from, for example,
1980 to 1981, the rows that show the cast members for 1980 are in one
table and those members from 1981 are in another.
Can this be done with nested loops? Do I need another query? Please
help if you can. I've struggled with this for a couple days and being
very new, have run out of stuff to try!
Thanks!
Tzuriel
I think nested loops will do what I want, but I can't seem to get them
right.
I have two tables, members and casts. I run a query as follows:
$sql_query="SEL ECT DISTINCT casts.yearID, members.memberN ame"
. " FROM members INNER JOIN casts ON members.memberI D =
casts.memberID"
. " WHERE (((casts.yearID ) In (SELECT DISTINCT yearID FROM
casts WHERE memberID='$id') ) AND ((casts.memberI D)<>'$id'));";
Which gets me the data I want to display using the following php:
$result=mysql_q uery($sql_query );
$num=mysql_numr ows($result);
echo "Cast data for: <b>$castmembe r</b>"; ID:$id<br>";
$year =mysql_result($ result,$i,"year ID");
echo " 1st season: <b>$year</b><p>";
//set up table for $result
print "<table width=200 border=0>\n";
print "\t<td><fon t face=arial size=1/><b>Cast Member</font></td>\n";
print "\t<td><fon t face=arial size=1/><b>Season</font></b></td>\n";
//loop through $result
$i=0;
while ($i < $num) {
$member=mysql_r esult($result,$ i,"memberName") ;
$year =mysql_result($ result,$i,"year ID");
print "<tr>\n";
print "\t<td><fon t face=arial size=1/>$member</font></td>\n";
print "\t<td><fon t face=arial size=1/>$year</font></td>\n";
print "</tr>\n";
$i++;
}
print "</table>\n";
?>
<?php echo "Cast data for: <b>",$castmembe r; ?><br></b>
However, the data is just one long list in the table with the two
columns Cast Member and Season. What I want to do is have a separate
table for each Season so that when yearID changes from, for example,
1980 to 1981, the rows that show the cast members for 1980 are in one
table and those members from 1981 are in another.
Can this be done with nested loops? Do I need another query? Please
help if you can. I've struggled with this for a couple days and being
very new, have run out of stuff to try!
Thanks!
Tzuriel
Comment