shawhey Posted April 11, 2011 Share Posted April 11, 2011 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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 11, 2011 Share Posted April 11, 2011 Try initializing the $count variable at 0. Quote Link to comment Share on other sites More sharing options...
shawhey Posted April 11, 2011 Author Share Posted April 11, 2011 I did try that, but then the problem becomes that the last row displays the last game on the right side. So, then I tried swapping the if and the else results, and it just takes me back to the original problem. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted April 11, 2011 Share Posted April 11, 2011 What is the value of $odd? Quote Link to comment Share on other sites More sharing options...
cssfreakie Posted April 11, 2011 Share Posted April 11, 2011 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> Quote Link to comment 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.