Jump to content

tzuriel

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

tzuriel's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [quote author=ToonMariner link=topic=120086.msg492391#msg492391 date=1167271437] [code]<?php $num=mysql_numrows($res);    $prev_show_val = NULL; $prev_year = NULL; while ($row = mysql_fetch_assoc($res)) { if ($prev_year != $row['yea']) {   //update the year here so no years repeat   $prev_year = $row['date'];   echo '<font face="arial" size="6" color="#2F4F4F">'  . $row['year']. '</font>'; }   if ($prev_show_val != $row['date']) {   //update the show date here so no dates repeat   $prev_show_val = $row['date'];   echo '<font face="arial" size="4" color="#2F4F4F">'  . $row['date']. '</font>'; } } ?> [/code] Try not to use teh font tag though - its deprecated - use <span> or better still h1 h2 etc and STYLE them with your css. [/quote] Thanks for the suggestion. I changed [code]<?php if ($prev_year != $row['yea']) {   //update the year here so no years repeat   $prev_year = $row['date']; ?> [/code] to [code]<?php if ($newyear != $row['year']) {   //update the year here so no years repeat   $newyear = $row['year']; ?> [/code] And it works the way I want it to. Maybe that's what you meant and just made a typo. Either way, thanks for pointing me in the right direction! Tzuriel
  2. Thanks.  I think that part is already fixed and I pasted an older version.  I actually just deleted one double quote and semi-colon: [code]<?php echo "Cast data for: <b>$castmember</b> ID:$id<br>";?>[/code] Any ideas on the looping question? Thanks! Tzuriel
  3. 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 which gets me the data I want to display with the following php: [code] <?php $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'));"; $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>[/code] 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.  Something like this html: [code]<title>Query Results</title> </head> <html> <body> Cast data for:  Denny Dillon</b> ID:10<br> 1st season:  1980</b><p>In 1980, Denny Dillon was in the cast with:</p><table border="0" width="200"> <tbody><tr><td>  Cast Member</b> </td> <td>  Season</b> </td> </tr><tr> <td> Gilbert Gottfried </td> <td> 1980 </td> </tr> <tr> <td> Gail Matthius </td> <td> 1980 </td> </tr> <tr> <td> Eddie Murphy </td> <td> 1980 </td> </tr> <tr> <td> Joe Piscopo </td> <td> 1980 </td> </tr> <tr> <td> Ann Risley </td> <td> 1980 </td> </tr> <tr> <td> Charles Rocket </td> <td> 1980 </table><p> In 1981, Denny Dillon was in the cast with:<p> <table border="0" width="200"> <tbody><tr><td>Cast Member</td> <td>Season</td> </tr><tr> <td> Eddie Murphy </td> <td> 1981 </td> </tr> <tr> <td> Joe Piscopo </td> <td> 1981 </td> </tr> <tr> <td> Brian Doyle-Murray </td> <td> 1981 </td> </tr> <tr> <td> Robin Duke </td> <td> 1981 </td> </tr> <tr> <td> Christine Ebersol </td> <td> 1981 </td> </tr> <tr> <td> Mary Gross </td> <td> 1981 </td> </tr> <tr> <td> Tim Kazurinsky </td> <td> 1981 </td> </tr> <tr> <td> Tony Rosato </td> <td> 1981 </td> </tr> </tbody></table> </body> </html>[/code] 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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.