ziggsstar Posted October 14, 2007 Share Posted October 14, 2007 Hi, Please forgive what might be an easy question to answer but I am very new to php. I am pulling records from a darts database which displays a players stats for his playing career and the query works as expected. What I am trying to do is - display the record set in a table with column headers and construct and write the data to the relevant columns (so far, so good). What I would like to achieve is, as the record set is looped through when the season.SeasonID changes (it is an integer) and increments to the next highest value, to be able to insert 2 blank table rows to visually separate each seasons results. At the moment I can output a perfectly formatted table with all results displayed but would like to separate block of seasons for easier readability. So the output would be (shortened version) Start of table Season | Name | W/L | Blah | Blah | Blah... 74/75 | J blog| W | data|data | data... blank row blank row 75/76 |J smith |L |data |data | data.. 75/76 |D Smith | W |data |data |data... blank row blank row.... ...... ....... End of table My sloppy code is below. Any help would be most appreciated. include("dbinfo.inc.php"); mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); // Select the darts database if (!@mysql_select_db('dartsdb')) { exit('<p>Unable to locate the darts ' . 'database at this time.</p>'); } $sql = mysql_query("SELECT season.SeasonID, players.playerName, players.surname, season.season, match_records.date, county.County, opponents.opponent, match_records.AorB, match_records.H_A, match_records.W_L, match_records.score1, match_records.score2, match_records.ave, match_records.tons, match_records.180, match_records.mom FROM players, county, match_records, opponents, season WHERE players.playerID = $playerid AND match_records.playerID = $playerid AND match_records.countyID = county.CountyID AND match_records.oppID = opponents.OppID AND season.SeasonID = match_records.seasonID"); ?> <table border='1'> <tr> <th>Season</th> <th>Date</th> <th>County opposition</th> <th>Opponent</th> <th>A/B</th> <th>H/A</th> <th>W/L</th> <th>Score</th> <th>|||</th> <th>|||</th> <th>Ave</th> <th>Ton's</th> <th>180's</th> <th>MoM's</th> </tr> <?php // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $sql )) { // Print out the contents of each row into a table echo "<tr><td class=\"tableborder\">"; echo $row['season']; echo "</td><td>"; echo date("d M", strtotime($row['date'])); echo "</td><td>"; echo $row['County']; echo "</td><td>"; echo $row['opponent']; echo "</td><td>"; echo $row['AorB']; echo "</td><td>"; echo $row['H_A']; echo "</td><td>"; echo $row['W_L']; echo "</td><td>"; echo $row['score1']; echo "</td><td>"; echo "-"; echo "</td><td>"; echo $row['score2']; echo "</td><td>"; echo $row['ave']; echo "</td><td>"; echo $row['tons']; echo "</td><td>"; echo $row['180']; echo "</td><td>"; echo $row['mom']; echo "</td></tr>"; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/73242-solved-inserting-blank-rows-into-the-output-of-a-recordset-according-to-value-of-an-int/ Share on other sites More sharing options...
Barand Posted October 15, 2007 Share Posted October 15, 2007 try <?php $lastSeason = ''; while($row = mysql_fetch_array( $sql )) { if ($row['season'] != $lastSeason) { if ($lastSeason) { echo "<tr><td colspan='14'> </td><tr><tr><td colspan='14'> </td><tr>"; } $lastSeason = $row['season']; } // Print out the contents of each row into a table echo "<tr><td class=\"tableborder\">"; echo $row['season']; echo "</td><td>"; echo date("d M", strtotime($row['date'])); echo "</td><td>"; echo $row['County']; echo "</td><td>"; echo $row['opponent']; echo "</td><td>"; echo $row['AorB']; echo "</td><td>"; echo $row['H_A']; echo "</td><td>"; echo $row['W_L']; echo "</td><td>"; echo $row['score1']; echo "</td><td>"; echo "-"; echo "</td><td>"; echo $row['score2']; echo "</td><td>"; echo $row['ave']; echo "</td><td>"; echo $row['tons']; echo "</td><td>"; echo $row['180']; echo "</td><td>"; echo $row['mom']; echo "</td></tr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73242-solved-inserting-blank-rows-into-the-output-of-a-recordset-according-to-value-of-an-int/#findComment-369573 Share on other sites More sharing options...
ziggsstar Posted October 15, 2007 Author Share Posted October 15, 2007 Barand, that works a treat! Thank you so much for your help :) regards, ziggsstar Quote Link to comment https://forums.phpfreaks.com/topic/73242-solved-inserting-blank-rows-into-the-output-of-a-recordset-according-to-value-of-an-int/#findComment-369579 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.