Jump to content

Showing tables side by side skips the first line


shawhey

Recommended Posts

Hi. I've got an array of results being shown in tables that I want to display 2x2. The only problem I'm having is that the second result skips the first line. Everything is good after that. I'm assuming it's because my CSS is going from last to first, and I don't understand why. Can anyone help me out? Here's how it keeps turning out:

 

http://moscowhockey.1free.ws/nhl_games.php

 

Here is my CSS code:

 

<style type="text/css">


.left-element {
   position: absolute;
   left: 100px;
   width: 50%;
   }

.right-element {
   position: absolute;
   right: 100px;
   width: 50%;
   } 

</style>

 

And this is the code for the tables:

 

$sql = mysql_query("SELECT * FROM games WHERE DATE(date) = '".$date."'");

$count = 1;


while($r = mysql_fetch_array($sql)) {

++$count;

if ( $odd == $count%2 )	{


?>

<div class="left-element">
<table border="1" width="300px">
<tr><td>Teams</td>
<td>Goals</td></tr>
<tr><td><?php echo "$r[away_team]"; ?></td>
<td><?php echo "$r[away_goals]"; ?></td></tr>
<tr><td><?php echo "$r[home_team]"; ?></td>
<td><?php echo "$r[home_goals]"; ?></td></tr>
<tr><td></td><td><?php echo "<p align='right'><a href='gamelogs/$r[id].php'>Box Score</a></p>"; ?></td></tr>
</div>

<?php

}

else	{

?>

<div class="right-element">
<table align="right" border="1" width="300px">
<tr><td>Teams</td>
<td>Goals</td></tr>
<tr><td><?php echo "$r[away_team]"; ?></td>
<td><?php echo "$r[away_goals]"; ?></td></tr>
<tr><td><?php echo "$r[home_team]"; ?></td>
<td><?php echo "$r[home_goals]"; ?></td></tr>
<tr><td></td><td><?php echo "<p align='right'><a href='gamelogs/$r[id].php'>Box Score</a></p>"; ?></td></tr>
</div>


<?php

	}

}

?>

 

Any help would be appreciated.

 

Cheers,

 

Chahe

Link to comment
Share on other sites

not sure what you want, but you can try this, not matter what the width is this works.

 

<?php error_reporting(E_ALL);
ini_set("display_errors", 1); ?>
<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />       
        <link type="text/css" rel="stylesheet" href="css/yourstyle.css" />
        <title></title>
<style type="text/css">
#matches{
    width:604px; /* width = 300*2+ (4x1 border)  but it can be any width bigger than 604*/
    background:#999;
    overflow:hidden;
}
.matchbox{
    width:300px;
    border:1px solid #000;
    float:left;
}
.fl{  
    clear:left;
}
</style>
    </head>
    <body>
        <div id="matches">
            <?php
//table format
$case = true;
for($i=0;$i<11;$i++){
   
   if($case == true && $i !== 0){ // so here it skips the first table, otherwise the clear in .fl facks up  */
       $class = 'fl';
   }else{
       $class = '';
   }
$tableformat =
<<<EOT
         <table class="matchbox $class">
            <tbody>
                <tr>
                    <td>Teams</td><td>Goals</td>
                </tr>
                <tr>
                    <td>MONTREAL CANADIENS</td><td>2</td>
                </tr>
                <tr>
                    <td>TORONTO MAPLE LEAFS</td><td>3</td>
                </tr>
                <tr>
                    <td>$i</td><td><span><a href="gamelogs/2.php">Box Score</a></span></td>
                </tr>
            </tbody>
           </table>
EOT;
echo $tableformat;
$case = !$case;
}
?> 
        </div>
    </body>
</html>

Link to comment
Share on other sites

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.