RJT Posted July 20, 2006 Share Posted July 20, 2006 [b]Full Code[/b][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') ?>[/code][b]Main Bit of Code that needs editing[/b][code]<?$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>"; } ?>[/code]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. :) Quote Link to comment https://forums.phpfreaks.com/topic/15099-need-help-with-formatting-in-php/ Share on other sites More sharing options...
manichean Posted July 20, 2006 Share Posted July 20, 2006 Hello RJT,I understand what you trying do do, but I have found some probs with ur code[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>[/code]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.[code]<?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;?>[/code]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) Quote Link to comment https://forums.phpfreaks.com/topic/15099-need-help-with-formatting-in-php/#findComment-60839 Share on other sites More sharing options...
RJT Posted July 20, 2006 Author Share Posted July 20, 2006 Thanks manichean, works perfectly! Thanks alot for the help :) Quote Link to comment https://forums.phpfreaks.com/topic/15099-need-help-with-formatting-in-php/#findComment-61023 Share on other sites More sharing options...
manichean Posted July 20, 2006 Share Posted July 20, 2006 No probs man glad i could help ;D Quote Link to comment https://forums.phpfreaks.com/topic/15099-need-help-with-formatting-in-php/#findComment-61028 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.