doddsey_65 Posted April 14, 2010 Share Posted April 14, 2010 Can some one please tell me where Im going wrong and why the layout isnt displaying 2 per row. I know its gotta be something with the closing tags, but ive been trying for hours to find it. <td id="col_main" valign="top" style="text-align:center;"> <div class="main_content"> <font size="2"><a href=""><b><em>NEWEST TUTORIALS</em></b></font><hr> <div class="tutorials_row" style="margin-bottom:0px;"> <table width="100%" border="2"><tr><td> <?php $i = 0; $result = mysql_query("SELECT * FROM tutorials ORDER BY added ASC LIMIT 4") or die(mysql_error()); while($row = mysql_fetch_object($result)) { if($i==0) { echo '<tr>'; } if($i==2) { echo '</tr><tr>'; $i=0; } ?> <table width="100%" border="1" cellspacing="0" cellpadding="0"> <tr> <td class="tutorials_left" valign="top"> <div class="tutorial_icon"><a href=""> <img src="<?php echo $row->path; ?>" alt="Tutorial Icon" class="tutorial_icon" width="50" height="50"></a> </div> </td> <td class="tutorials_right" valign="top"> <div class="tutorial_title"><a href="">Render Layers</a> </div> <div class="tutorial_uploaded"> Uploaded by <a href=""><?php echo $row->name; ?></a> on <em><?php echo $row->added; ?></em> </div> <div class="tutorial_cat">Category: <a href=""><?php echo $row->category; ?></a> </div> </td> </tr> </table> <div class="tutorial_bar"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="views">Views: <em><?php echo $row->views; ?></em></td> <td class="comments"><a href="" title="Tutorial Comments">Comments:</a> <em>3</em></td> <td class="rating">Rating: <a href="">4.76</a></td> </tr> </table> </div> </div> </td><td> <?php $i++; } ?> </tr> </table> </tr> </table> </div> Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/ Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 Because you don't have any td tags in your loop at all? and also you are not incrementing $i with $i++ you keep resetting it to 0 every time Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041705 Share on other sites More sharing options...
doddsey_65 Posted April 14, 2010 Author Share Posted April 14, 2010 i have several <td> tags in the loop Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041707 Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 i have several <td> tags in the loop K i didn't look far enough hold on. Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041710 Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 Jesus this code is messy as hell. One thing I'm seeing is you aren't restarting your td tag in ur if($i==2) You should prob have a td tag right after that opening tr tag Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041712 Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 You should scrap that entire first half and start over again. Take a look at the html it's producing. I guarantee you have a few extra tr's in there and a few missing td's. Take a look at what that loop is doing. You are not adding td's in that loop and you are putting a tr inside of that initial td tag you placed outside of the loop. Stuff is crazy. Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041713 Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 Also you have two table closing tags on there. No td closing tag at the end to close the mysterious floating td tag you have at the top. I hope this is incomplete code because I am very confused. Run your site. Right click it and view the source then post the source for your site at the specific area your tables are being created. That will make it a lot easier to see what extra stuff is being placed in and what is missing. Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041726 Share on other sites More sharing options...
doddsey_65 Posted April 14, 2010 Author Share Posted April 14, 2010 heres the source: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>The Vault | A Tutorial Repository</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="stylesheet.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <br> <div id="logo"> <img src="images/main_logo.png"> </div> <div id="container"> <div id="dyn_container"> <div id="main_container"> <div id="mainheader"> <img src="images/categories.png"><img src="images/middle.png"><img src="images/tutorials.png"></div> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td id="left" valign="top"> <div id="left_categories"> <div class="cat_content"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Animation</a></td> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Basics</a></td> </tr> <tr> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Cloth</a></td> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Compositing</a></td> </tr> <tr> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Dynamics</a></td> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Fluid</a></td> </tr> <tr> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Game Engine</a></td> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">General</a></td> </tr> <tr> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Lighting</a></td> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Modelling</a></td> </tr> <tr> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Modifiers</a></td> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Particles</a></td> </tr> <tr> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Rendering</a></td> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Rigging</a></td> </tr> <tr> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Scripts</a></td> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Sculpting</a></td> </tr> <tr> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Texturing</a></td> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">Tips And Tricks</a></td> </tr> <tr> <td class="icon"><img src="images/icons/ball.png"></td> <td class="title" valign="bottom"><a href="">UV Mapping</a></td> </tr> </table> </div> <div class="left_cat_title" align="center"> <a href="#">Weekly Quiz</a> </div> <div class="cat_content"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <form action ="/thevault/index.php" method=POST> <td class="title" valign="bottom" align="center">When was Blender 3D first Released?</td></tr> <tr><td> <div align="center"> <input type = radio name=options value=1995>1995 <input type = radio name=options value=1998>1998 <input type = radio name=options value=2000>2000 <input type = radio name=options value=2002>2002 </div></tr></td><tr><td><br> <div align="center"> <input type=submit value=Submit name=poll_btn></form> </div></td> </tr> </table> </div> <td id="col_main" valign="top" style="text-align:center;"> <div class="main_content"> <font size="2"><a href=""><b><em>NEWEST TUTORIALS</em></b></font><hr> <div class="tutorials_row" style="margin-bottom:0px;"> <table width="100%" border="2"><tr><td> <tr> <table width="100%" border="1" cellspacing="0" cellpadding="0"> <tr> <td class="tutorials_left" valign="top"> <div class="tutorial_icon"><a href=""> <img src="tutcovers/hamishsky.jpg" alt="Tutorial Icon" class="tutorial_icon" width="50" height="50"></a> </div> </td> <td class="tutorials_right" valign="top"> <div class="tutorial_title"><a href="">Render Layers</a> </div> <div class="tutorial_uploaded"> Uploaded by <a href="">Creating Sky</a> on <em>2010-04-01</em> </div> <div class="tutorial_cat">Category: <a href="">17</a> </div> </td> </tr> </table> </div> </td><td> <table width="100%" border="1" cellspacing="0" cellpadding="0"> <tr> <td class="tutorials_left" valign="top"> <div class="tutorial_icon"><a href=""> <img src="tutcovers/hamishlava.jpg" alt="Tutorial Icon" class="tutorial_icon" width="50" height="50"></a> </div> </td> <td class="tutorials_right" valign="top"> <div class="tutorial_title"><a href="">Render Layers</a> </div> <div class="tutorial_uploaded"> Uploaded by <a href="">Making Lava</a> on <em>2010-04-01</em> </div> <div class="tutorial_cat">Category: <a href="">1</a> </div> </td> </tr> </table> </div> </td><td> </tr><tr> <table width="100%" border="1" cellspacing="0" cellpadding="0"> <tr> <td class="tutorials_left" valign="top"> <div class="tutorial_icon"><a href=""> <img src="tutcovers/hamishtext.jpg" alt="Tutorial Icon" class="tutorial_icon" width="50" height="50"></a> </div> </td> <td class="tutorials_right" valign="top"> <div class="tutorial_title"><a href="">Render Layers</a> </div> <div class="tutorial_uploaded"> Uploaded by <a href="">3D Text</a> on <em>2010-04-01</em> </div> <div class="tutorial_cat">Category: <a href="">10</a> </div> </td> </tr> </table> </div> </td><td> <table width="100%" border="1" cellspacing="0" cellpadding="0"> <tr> <td class="tutorials_left" valign="top"> <div class="tutorial_icon"><a href=""> <img src="tutcovers/hamishlogo.jpg" alt="Tutorial Icon" class="tutorial_icon" width="50" height="50"></a> </div> </td> <td class="tutorials_right" valign="top"> <div class="tutorial_title"><a href="">Render Layers</a> </div> <div class="tutorial_uploaded"> Uploaded by <a href="">3D Logo</a> on <em>2010-04-01</em> </div> <div class="tutorial_cat">Category: <a href="">10</a> </div> </td> </tr> </table> </div> </td><td> </tr> </table> </tr> </table> </div> Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041732 Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 Do you see a problem in this area of your code? <div class="tutorials_row" style="margin-bottom:0px;"> <table width="100%" border="2"><tr><td> <tr> You shouldn't put a <tr> tag inside of your <td> tag so change this line <table width="100%" border="2"><tr><td> to this <table width="100%" border="2"> Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041742 Share on other sites More sharing options...
doddsey_65 Posted April 14, 2010 Author Share Posted April 14, 2010 okay ive tidied up the code a bit: <td id="col_main" valign="top" style="text-align:center;"> <div class="main_content"> <font size="2"><a href=""><b><em>NEWEST TUTORIALS</em></b></font><hr> <div class="tutorials_row" style="margin-bottom:0px;"> <table width="100%" border="5"> <tr> <td> <?php $i = 0; $result = mysql_query("SELECT * FROM tutorials ORDER BY added ASC LIMIT 4") or die(mysql_error()); while($row = mysql_fetch_object($result)) { if($i==2) { echo '</tr><tr>'; $i=0; } ?> <table width="50%" border="10" cellspacing="0" cellpadding="0"> <tr> <td class="tutorials_left" valign="top"> <div class="tutorial_icon"> <img src="<?php echo $row->path; ?>" alt="Tutorial Icon" class="tutorial_icon" width="50" height="50"></a> <?php echo $i; ?> </div> </td> <td class="tutorials_right" valign="top"> <div class="tutorial_title"><a href=""><?php echo $row->name; ?></a> </div> <div class="tutorial_uploaded"> Uploaded by <a href=""><?php echo $row->fullname; ?></a> on <em><?php echo $row->added; ?></em> </div> <div class="tutorial_cat">Category: <a href=""><?php echo $row->category; ?></a> </div> </td> </tr> </table> <div class="tutorial_bar"> <table width="50%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="views">Views: <em><?php echo $row->views; ?></em></td> <td class="comments"><a href="" title="Tutorial Comments">Comments:</a> <em>3</em></td> <td class="rating">Rating: <a href="">4.76</a></td> </tr> </table> </div> <?php $i++; } ?> </td> </tr> </table> </div> </div> </td> Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041744 Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 Thankyou. Just a little more should fix it up. For this block of code <table width="100%" border="5"> <tr> <td> <?php $i = 0; $result = mysql_query("SELECT * FROM tutorials ORDER BY added ASC LIMIT 4") or die(mysql_error()); while($row = mysql_fetch_object($result)) { if($i==2) { echo '</tr><tr>'; $i=0; } ?> change it to this <table width="100%" border="5"><tr> <?php $i = 0; $result = mysql_query("SELECT * FROM tutorials ORDER BY added ASC LIMIT 4") or die(mysql_error()); while($row = mysql_fetch_object($result)) { echo '<td>'; if($i%2 == 0) { echo '</tr><tr>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041754 Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 And change this <?php $i++; } ?> to this <?php echo '</td>'; $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041755 Share on other sites More sharing options...
doddsey_65 Posted April 14, 2010 Author Share Posted April 14, 2010 sorry but ive fixed it, thanks for your help though. after i tidied it up it was easier. I added a <td> to the end of if ($i == 2) { echo '</tr><tr>'; // added td here } Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041764 Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 sorry but ive fixed it, thanks for your help though. after i tidied it up it was easier. I added a <td> to the end of if ($i == 2) { echo '</tr><tr>'; // added td here } Np. I would advise making that switch to using the mod operator though like I recommended. It allows for easier expandability in your system. It will make it so every number that can evenly be divided by 2 will set off the if. Quote Link to comment https://forums.phpfreaks.com/topic/198524-another-table-layout/#findComment-1041822 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.