blueman378 Posted February 5, 2008 Share Posted February 5, 2008 hi guys i have this code <?php function GetAction(){ global $database; $q = "SELECT * FROM " . Games . " WHERE category='Action / Adventure' ORDER BY `gName` ASC "; $result = $database->query($q) or die("Error: " . mysql_error()); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if( $num_rows == 0 ){ return '<font size="2">Games not found!</font>'; } /* Display table contents */ $content = "<table border=\"0\" cellspacing=\"10\" ><tr> "; while( $row = mysql_fetch_assoc($result) ) { $content .= " <td style='width: 10%;' valign='top'><a href='showgame.php?game=$row[gName]'><img border='1' src='thumbs_ins/$row[gThumb]'></a> </td><td style='width: 40%;' valign='top'><b> <a href='showgame.php?game=$row[gName]'>$row[gName]</a></b><br>$row[gDescription]</td> "; } $content .= "</tr></table><br>\n"; return $content; } // You can echo GetAction(); ?> but that means that if i have 12 results i get [] [] [] [] [] [] [] [] [] [] [] [] but what i am looking for is [] [] [] [] [] [] [] [] [] [] [] [] so i would want to insert a </tr><tr> after every second run, any ideas? Quote Link to comment Share on other sites More sharing options...
beansandsausages Posted February 5, 2008 Share Posted February 5, 2008 i would look at xhtml b4 i do any php, <br><b><font color=color><font size4> are all so no no, But yeah just add a <tr> : $content .= " <td style='width: 10%;' valign='top'><a href='showgame.php?game=$row[gName]'><img border='1' src='thumbs_ins/$row[gThumb]'></a> </td><td style='width: 40%;' valign='top'><b> <a href='showgame.php?game=$row[gName]'>$row[gName]</a></b><br>$row[gDescription]</td> "; } $content .= "</tr><tr></td></table><br>\n"; Sould work. Quote Link to comment Share on other sites More sharing options...
blueman378 Posted February 5, 2008 Author Share Posted February 5, 2008 it still has the exact same effect Quote Link to comment Share on other sites More sharing options...
mem0ri Posted February 5, 2008 Share Posted February 5, 2008 You're going to want to run an incrementation on your while loop (like an $x++) and check every loop through of whether the remainder (x % 2) == 1. If so, </td></tr>...else just </td>...conversely, you'll have to switch between <tr><td> and just <td> at the start of each while loop. It's easily done...just did it earlier today actually...just can't pull up the code at the moment. Quote Link to comment Share on other sites More sharing options...
haku Posted February 5, 2008 Share Posted February 5, 2008 I use this construct: $j = 1 echo "<tr>"; for($i = 0; $i < something; $i++) { // echo your <td></td> here with the applicable data inside the tags if ($j % 2 = 0) { echo "</tr><tr>"; } $j += 1; } echo "</tr>";[code] This sets an opening <tr> tag at the start, then fills in one <td></td> tag, goes back to the start of the loop, echos another <td></td> then echoes a closing </tr> tag, and then another opening <tr> tag. Finally after the loop is finished, it echoes a closing </tr> tag to finish everything off. [/code] 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.