Jump to content


Photo

Need help with <td> formatting in PHP


  • Please log in to reply
3 replies to this topic

#1 RJT

RJT
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 03:37 AM

Full Code
<?php include('header.php') ?>

<?
include("dbinfo.inc.php");
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM roster ORDER BY name";
$result=mysql_query($query);

$num=mysql_numrows($result); 

mysql_close();


?>
<center>
<table align="center" max-width="480" width="480" cellpadding="2" cellspacing="0" border="1" bordercolor="#000000">
      <tr>
      <td width=480 background="images/backgrounds/menubg.jpg" align="center"><font face="verdana" color="#FF0000" size="2"><b>
Viewing All Wrestlers (<?php echo "$num" ?>)
      </td>
      </tr>

      <tr>

      <td bgcolor="333333" valign="top" width="480" align="left">
      <font face="verdana" size="2" color=black>
<table width='480'>
<?
$i=0;
$first_letter_old="";
while ($i < $num) {
    $name=mysql_result($result,$i,"name");
    $image=mysql_result($result,$i,"image");
    ++$i;
echo "<td bgcolor=000000 valign='top' width='100' align='left'><center><a href='wrestler.php?name=$name'><img border=0 width=100 src='http://www.reef-break.com/scw/images/superstars/$image.jpg'></a><br><font face=verdana size=1 color=red><a href='wrestler.php?name=$name'>$name</a></font></center></td>"; } 
?>
</table>
</td>
</tr>
</table>

<?php include('footer.php') ?>

Main Bit of Code that needs editing
<?
$i=0;
$first_letter_old="";
while ($i < $num) {
    $name=mysql_result($result,$i,"name");
    $image=mysql_result($result,$i,"image");
    ++$i;
echo "<td bgcolor=000000 valign='top' width='100' align='left'><center><a href='wrestler.php?name=$name'><img border=0 width=100 src='http://www.reef-break.com/scw/images/superstars/$image.jpg'></a><br><font face=verdana size=1 color=red><a href='wrestler.php?name=$name'>$name</a></font></center></td>"; } 
?>


I need to somehow make the code make a < br> after 5 <td> rows are printed so the maximum amount of rows is 5. I currently have no idea how to do this, so help would be appreciated.  :)

#2 manichean

manichean
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 20 July 2006 - 05:03 AM

Hello RJT,

I understand what you trying do do, but I have found some probs with ur code
<table width='480'> /*need to use escape chars to make use of " when using equals following the web standards*/
<?
$i=0;
$first_letter_old=""; /* dont know what this is for but im sure u got a valid reason, I have not included it in my solution */
while ($i < $num) {
    $name=mysql_result($result,$i,"name");
    $image=mysql_result($result,$i,"image");
    ++$i;
echo "<td bgcolor=000000 valign='top' width='100' align='left'><center><a href='wrestler.php?name=$name'><img border=0 width=100 src='http://www.reef-break.com/scw/images/superstars/$image.jpg'></a><br><font face=verdana size=1 color=red><a href='wrestler.php?name=$name'>$name</a></font></center></td>"; } 
?>
</table>
ok bascially you need a tr tag after your table declaration you are jumping straight into a td, minor mistake after too much coding  :-X, so now it depends on you do you want 5 td's per row ? or the br after 5 td's i would go for the tr option but here is the edited code for you.
<?php
$i=0;
$j=0;
$stringToEcho;
$bolEndTr = false;
$stringToEcho = "<table width=\"480\">\n";
$stringToEcho .= "<tr>\n";
while ($i < $num) {
    if ($num < 5){
        $bolEndTr = true; /*We need to have this to make sure if there are less than 5 rows we must close the tr tag */
    }
    $name=mysql_result($result,$i,"name");
    $image=mysql_result($result,$i,"image");
    ++$i;
    $stringToEcho .= "<td bgcolor=\"#000000\" valign=\"top\" width=\"100\" align=\"left\">\n";
    $stringToEcho .= "<center>\n";
    $stringToEcho .= "<a href=\"wrestler.php?name=$name\">\n";
    $stringToEcho .= "<img border=\"0\" width=\"100\" src=\"http://www.reef-break.com/scw/images/superstars/$image.jpg\" />\n";
    $stringToEcho .= "</a>\n";
    $stringToEcho .= "<br>\n";
    $stringToEcho .= "<font face=\"verdana\" size=\"1\" color=\"red\">\n";
    $stringToEcho .= "<a href=\"wrestler.php?name=$name\">$name</a>\n";
    $stringToEcho .= "</font>\n";
    $stringToEcho .= "</center>\n";
    $stringToEcho .= "</td>\n";
    $j++;
    if ($j == 5){
        $stringToEcho .= "</tr>\n";
        $j=0;
    }
} 
if ($bolEndTr){
    $stringToEcho .= "</tr>\n";
}
$stringToEcho .= "</table>\n";
echo $stringToEcho;
?>
I hope this helps you, its also a good idea to make use of CSS for styling the elements you are displaying instead of having them in the page. It makes for easier editing
8)

#3 RJT

RJT
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 20 July 2006 - 02:22 PM

Thanks manichean, works perfectly! Thanks alot for the help :)

#4 manichean

manichean
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 20 July 2006 - 02:25 PM

No probs man glad i could help  ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users