Jump to content

[SOLVED] html table created wrong due to $i


rockon

Recommended Posts

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 :)

 

Link to comment
Share on other sites

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>';

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.