rockon Posted September 27, 2009 Share Posted September 27, 2009 Hi all, I'm a beginner when it comes to PHP. I'm editing a pre-made script I purchased to theme it to my liking but I have run in to a problem. It's a lyric website and I want A - B - C - D etc etc going across the top but the way it's coded makes the A have a <tr> of it's own. Here's the code: <table width="790px" cellpadding="0" cellspacing="0"> <?php $head_letters = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'N', 'M', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); $i = 0; while($i < COUNT($head_letters)){ if(($i % 100) == 0) echo "<tr>"; echo "<td align='center'"; if(strlen($head_letters[$i]) > 0) echo " style='cursor:pointer;'"; echo "><a href=\"browse-$head_letters[$i]_page-0.html\" class='menualpha'><b>$head_letters[$i]</b></a></td>"; if(($i % 100) == 0) echo "</tr>"; $i++; } ?> </table> The site is: www.megalyrics.net and the demo log in is: username: test password: test any ideas why the letter A is being put in its own <tr> ?? Hope someone can help! thanks Quote Link to comment https://forums.phpfreaks.com/topic/175726-solved-html-table-created-wrong-due-to-i/ Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 The site won't load for me, but it doesn't matter. The reason that A is being put inside of it's own row is because the two conditionals ($i % 100) == 0 are only being fired when $i = 0. If you want to make them all be inside one <tr>, you should remove that from the loop. I don't see the point of if(strlen($head_letters[$i]) > 0) because that would only evaluate to true if one of the elements in $head_letters is empty, which since that array is hard-coded shouldn't be a problem. Try: echo '<tr>'; for($i = 0;$i < count($head_letters);$i++) echo "<td align='center' style='cursor:pointer;'><a href=\"browse-{$head_letters[$i]}_page-0.html\" class='menualpha'><b>{$head_letters[$i]}</b></a></td>"; echo '</tr>'; Quote Link to comment https://forums.phpfreaks.com/topic/175726-solved-html-table-created-wrong-due-to-i/#findComment-926047 Share on other sites More sharing options...
rockon Posted September 27, 2009 Author Share Posted September 27, 2009 Lovely. That worked great Quote Link to comment https://forums.phpfreaks.com/topic/175726-solved-html-table-created-wrong-due-to-i/#findComment-926053 Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 Lovely. That worked great Just check "Topic Solved" in the bottom left, Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/175726-solved-html-table-created-wrong-due-to-i/#findComment-926056 Share on other sites More sharing options...
Alex Posted September 27, 2009 Share Posted September 27, 2009 Whoops, unintentional post. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/175726-solved-html-table-created-wrong-due-to-i/#findComment-926067 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.