Nested loops help please?



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="SELECT DISTINCT casts.yearID, members.memberName"
. " FROM members INNER JOIN casts ON members.memberID =
casts.memberID"
. " WHERE (((casts.yearID) In (SELECT DISTINCT yearID FROM
casts WHERE memberID='$id')) AND ((casts.memberID)<>'$id'));";


Which gets me the data I want to display using the following php:

$result=mysql_query($sql_query);

$num=mysql_numrows($result);

echo "Cast data for: <b>$castmember</b>"; ID:$id<br>";
$year =mysql_result($result,$i,"yearID");

echo " 1st season: <b>$year</b><p>";

//set up table for $result
print "<table width=200 border=0>\n";
print "\t<td><font face=arial size=1/><b>Cast Member</font></td>\n";
print "\t<td><font face=arial size=1/><b>Season</font></b></td>\n";

//loop through $result
$i=0;
while ($i < $num) {

$member=mysql_result($result,$i,"memberName");
$year =mysql_result($result,$i,"yearID");
print "<tr>\n";
print "\t<td><font face=arial size=1/>$member</font></td>\n";
print "\t<td><font face=arial size=1/>$year</font></td>\n";
print "</tr>\n";


$i++;

}
print "</table>\n";
?>


<?php echo "Cast data for: <b>",$castmember; ?><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

.



Relevant Pages

  • Re: Bill OReilly lashes out at Law & Order executive producer
    ... in the form of scripts, signed by all members of all three casts, to ... be sold at auction. ...
    (talk.politics.guns)
  • Re: my handy-dandy, "coding style" script
    ... Bearing in mind that some casts may have been put in when struct ... members had other values, may be needed on some hardware but not ...
    (Linux-Kernel)
  • Re: Bill OReilly lashes out at Law & Order executive producer
    ... in the form of scripts, signed by all members of all three casts, to ... be sold at auction. ...
    (talk.politics.guns)
  • Re: Syntax needed to get needed reports
    ... what you posted as a query will not work for you because you must ... I ran the update query below to see what happens. ... > UPDATE Members ... > WHERE [Hobbies] Is Not Null; ...
    (microsoft.public.access.gettingstarted)
  • Re: Does DateDiff Have A Bug
    ... I changed the form (Members) RecordSource back to my Main ... Now I just use the results from the query and everything works better than ... MemberID FirstName LastName EntryDate DaysRemaining ... calculated field within it's calculation) would look like; ...
    (microsoft.public.access.formscoding)