PDA

View Full Version : Limit Number Of Cells (<td>)


sebthib55
August 21st, 2006, 06:22 AM
I have a script using PHP... The only problem is I cannot limit the number of cells one beside each other. This script displays avatars. Sadly, if you have 8 avatars, you get 8 cells one beside each other. That is very ugly and ruins the page, since you have to scroll. How can I limit the number to, lets say, 5 cells per row.
Thanks Seb...

Heres my code:

//start hidden avatars
$hiddenavycount=run_query("SELECT * FROM phpqa_hid_avs WHERE username='$exist[1]' AND type='hidden' ORDER BY avatar ASC");
$hiddenavycount2=mysql_num_rows($hiddenavycount);

if($hiddenavycount2 >=1){
run_query("SELECT * FROM phpqa_hid_avs WHERE name=$exist[1]");
echo "<hr>
<br>Hidden Avatars:";
echo "<p><table width='30%' cellpadding='5' cellspacing='1' border='0'>";
echo "<form action='Arcade.php?action=settings&p=avatar' method='POST'>";
while ($b = mysql_fetch_array($hiddenavycount)) {
$avatar = $b['avatar'];


echo "<td><center><img src='hidavs/$avatar.gif' border=0></a><br>$avatar<br>[<input type='radio' name='remoteavatar' value='hidavs/$avatar.gif'>]<a href=\"javascript:document.getElementsByName('remoteavata r')[$x].checked='checked';void(0);\"></td>";
}
echo"</table>";
echo "<br><br><input type=submit name='submit' value='Select'></form>";
}
//end hidden avatars

Buzz
August 21st, 2006, 08:00 AM
You're missing all <tr> tags


This will work provided all the rows have the same number of sells.
If there are 8 cells and you want 5 per row.. then you've got to get around the issue of uneven cells in each row.
If it were me.. I'd just use divs and float them. Then it doesn't matter how many you have, they'll break naturally to fill a space.


//start*hidden*avatars
$hiddenavycount=run_query("SELECT***FROM*phpqa_hid_avs*WHERE*username='$exist[1]'*AND*type='hidden'*ORDER*BY*avatar*ASC");
$hiddenavycount2=mysql_num_rows($hiddenavycount);

if($hiddenavycount2*>=1){
run_query("SELECT***FROM*phpqa_hid_avs*WHERE*name=$exist[1]");
echo*"<hr>
<br>Hidden*Avatars:";
echo*"<p><table*width='30%'*cellpadding='5'*cellspacing='1'* border='0'><tr>";
echo*"<form*action='Arcade.php?action=settings&p=avatar'*method='POST'>";
$i =0;
while*($b*=*mysql_fetch_array($hiddenavycount))*{
$avatar*=*$b['avatar'];


echo*"<td><center><img*src='hidavs/$avatar.gif'*border=0></a><br>$avatar<br>[<input*type='radio'*name='remoteavatar'*value='hida vs/$avatar.gif'>]<a*href=\"javascript:document.getElementsByName('remoteavata r')[$x].checked='checked';void(0);\"></td>";
if ($i == 5) { echo '</tr><tr>'; }

$i++;
}
echo"</tr></table>";
echo*"<br><br><input*type=submit*name='submit'*value='Select'></form>";
}
//end*hidden*avatars*

sebthib55
August 21st, 2006, 06:22 PM
Well if I'd use divs, how would I insert that in my code? Sorry, kind of clueless... :p

Buzz
August 21st, 2006, 07:07 PM
<?php
query and stuff

echo '<table>
<tr>
<td>';

while ($foo = mysql_fetch($blah){
$yadda = $foo->this;

echo '<div class="av">'.$yadda.'</div>';
}

echo '</td>
</tr>
</table>';

?>


Then in the style sheet you'd control the div.



div.av {
float: left;
margin: 10px;
padding: 5px;
text-align: center;
]

sebthib55
August 21st, 2006, 08:13 PM
I did exactly what you told me. Sadly, all avatars are placed in one column. They are all 1 on top of the other in one big column. :(

http://img361.imageshack.us/img361/6296/screenshotpk4.gif

Here is my code:

echo "<p><table width='30%' cellpadding='5' cellspacing='1' border='0'>
<tr><td>";
echo "<form action='Arcade.php?action=settings&p=avatar' method='POST'>";

while ($b = mysql_fetch_array($hiddenavycount)) {
$avatar = $b['avatar'];
echo "<div class='av'><center><img src='hidavs/$avatar.gif' border=0>
<br>$avatar
<br>[<input type='radio' name='remoteavatar' value='hidavs/$avatar.gif'>]
<a href=\"javascript:document.getElementsByName('remoteavata r')[$x].checked='checked';void(0);\"></div>";
}
echo '</td>
</tr>
</table>';

echo "<br><br><input type=submit name='submit' value='Select'></form>";
}

Buzz
August 21st, 2006, 09:20 PM
Did you add the CSS properties to the style sheet?

Don't have a style sheet? Then add this to the div tag


<div style="float: left;">

sebthib55
August 21st, 2006, 09:22 PM
Yes, I added it to my style sheet already.:(


div.av {
float: left;
margin: 10px;
padding: 5px;
text-align: center;
}

Buzz
August 21st, 2006, 09:31 PM
Remove the <center> tag from your code. it's deprecated and should never be used any more.

Does your file have a DOCTYPE declared at the top?

You can also try removing div.av and jsut putting .av in the style sheet.

sebthib55
August 21st, 2006, 09:38 PM
Nope it doesn't have a DOCTYPE.
I removed the center tag and also renamed div.av.

I still have the same problem. :(

Buzz
August 21st, 2006, 09:44 PM
You need to add a DOCTYPE at the very beginning of the file. Before any other HTML is passed to the browser. Generally all files should start with something like this.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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" />


You might also want to browse the w3 site [http://www.w3.org/] for some building tips. The problems you are having are due to malformed pages.

sebthib55
August 21st, 2006, 09:48 PM
That didn't solve the problem. :(

Buzz
August 22nd, 2006, 12:46 AM
I don't know what else to tell you. Everything I've explained does work. I've used it for years on several sites.

http://www.weichertcreative.com

Without seeing the entire page I could continue to speculate on what the problem may be for the next 10 years.

sebthib55
August 22nd, 2006, 01:12 AM
I don't know because I gave you the entire code :(

Buzz
August 22nd, 2006, 01:52 AM
That can not possibly be the entire code.. there's no html tags no body tag no link to a stylesheet. If that is your entire page, you need to go back to the beginning and learn basic HTML web building before even messing with PHP.

sebthib55
August 22nd, 2006, 09:22 PM
No... well I obviously have my
<?php

?> and stuff like that...

I just showed you the main part. I know lots of PHP and stuff. I mastered HTML. I created my site http://sebbyarcade.net.ms :p

Buzz
August 22nd, 2006, 10:31 PM
uhm... that page contains 184 errors.

sebthib55
August 22nd, 2006, 10:49 PM
Everything seems to run fine though...

Buzz
August 22nd, 2006, 11:58 PM
Well running fine and coded well are different. You can attache an alternator to a car with a string and duck tape and it'll run... whether or not it'll last is another matter.

Much of the reason the Div code above isn't working must be due to the way your page is formed. IT's standard code and should work perfectly in any correctly formatted page.

sebthib55
August 24th, 2006, 07:44 AM
Yea you got a point there. I am a semi-beginner so I am learning. :p Eventually I will learn my mistakes. I just wonder how I would be able to get something that will spot all my 100s of errors so I can fix them easily.... :p