Ameslee Posted December 15, 2006 Share Posted December 15, 2006 hi hope someone can help me, here is the code i am having troble with:[code] <?php $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $query = "SELECT * FROM news"; $mysql_result=mysql_query($query,$conn); $row=mysql_fetch_row($mysql_result); echo("<table width=100%>"); $i=1; while(($row!="") && ($i<=4)) { $row[1] = wordwrap($row[1], 80, '<br />', true); echo "<tr>"; echo "<td>$row[1]</td></tr>"; echo "<hr>"; $row=mysql_fetch_row($mysql_result); $i++; } ?>[/code]Firstly it is not displaying anymore than one record and where the [code]<hr>[/code] is suppose to display, its not. The [code]<hr>[/code] comes first then the block of text. But i need the block of text in between the [code]<hr>[/code] Its also displaying recorded 2, instead of the first one, first.Can anyone help? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/30731-code-not-working/ Share on other sites More sharing options...
Ameslee Posted December 15, 2006 Author Share Posted December 15, 2006 ive been able to get more than one to display, but the hr's are not displaying in the correct place, in between the records Link to comment https://forums.phpfreaks.com/topic/30731-code-not-working/#findComment-141634 Share on other sites More sharing options...
Hypnos Posted December 15, 2006 Share Posted December 15, 2006 Try this:[code=php:0] $row=mysql_fetch_row($mysql_result); $i=1; while(($row!="") && ($i<=4)) { echo "<table width=\"100%\">"; $row[1] = wordwrap($row[1], 80, '<br />', true); echo "<tr>"; echo "<td>$row[1]</td></tr></table>"; echo "<hr>"; $row=mysql_fetch_row($mysql_result); $i++; }[/code]You can't have an [code=php:0]<hr>[/code] tag inbetween <tr>s. But you could do something like:[code=php:0]<table><tr><td>1</td></tr><tr><td><hr></td></tr><tr><td>2</td></tr>...</table>[/code]Just make sure your content is always between <td> tags when inside a table. Link to comment https://forums.phpfreaks.com/topic/30731-code-not-working/#findComment-141635 Share on other sites More sharing options...
Psycho Posted December 15, 2006 Share Posted December 15, 2006 Your are trying to display <hr>'s inbetween table elements. You either need to disply them before or after the table OR put them within <TD> tags. I think this may be what you want:[code]<?php $hostname = localhost; $username = ; $password = ; $conn = mysql_connect($hostname, $username, $password) or die(mysql_error()); $connection = mysql_select_db("greenac_VORNExpo", $conn); $query = "SELECT * FROM news"; $mysql_result=mysql_query($query,$conn); echo "<table width=100%>"; $i=0; while($row=$row=mysql_fetch_row($mysql_result)) { $i++; if ($i==1) { echo "<tr>\n"; } echo "<td>" . wordwrap($row[1], 80, '<br />', true) . "</td>"; if ($i==4) { echo "</tr>\n"; echo "<tr><td colspan=\"4\"><hr></td></tr>\n"; $i = 0; } } if ($i!=0) { for ($i; $i<4; $i++) { echo "<td> </td>"; } echo "</tr>"; } echo "</table>"; ?>[/code] Link to comment https://forums.phpfreaks.com/topic/30731-code-not-working/#findComment-141636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.