Jump to content

[SOLVED] inserting blank rows into the output of a recordset according to value of an int


Recommended Posts

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>";

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>"; 

} 
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.