cheechm Posted August 28, 2007 Share Posted August 28, 2007 Hi, For some reason with this script I get the titles (Event/Year/Team) after every row. echo "<table class=\"events\" width=\"90%\">"; echo "<tr>"; echo "<th>Event</th>"; echo "<th>Year</th>"; echo "<th>Team</th>"; echo "</tr>"; echo "<tr><td>"; echo "$row[EventName]"; echo "</td>"; echo "<td>"; echo "$row[Year]"; echo "</td>"; echo "<td>"; printf($link2, $row['EventName'], $row['Year']); echo "</td></tr>"; echo "</table>"; This is a search, so there won't always be data in the table. Quote Link to comment Share on other sites More sharing options...
Neptunus Maris Posted August 28, 2007 Share Posted August 28, 2007 Hi, For some reason with this script I get the titles (Event/Year/Team) after every row. echo "<table class=\"events\" width=\"90%\">"; echo "<tr>"; echo "<th>Event</th>"; echo "<th>Year</th>"; echo "<th>Team</th>"; echo "</tr>"; echo "<tr><td>"; echo "$row[EventName]"; echo "</td>"; echo "<td>"; echo "$row[Year]"; echo "</td>"; echo "<td>"; printf($link2, $row['EventName'], $row['Year']); echo "</td></tr>"; echo "</table>"; This is a search, so there won't always be data in the table. What the heck Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 28, 2007 Share Posted August 28, 2007 I don't understand...can you post a link to the page in action and explain more? Quote Link to comment Share on other sites More sharing options...
Neptunus Maris Posted August 28, 2007 Share Posted August 28, 2007 echo "<table class=\"events\" width=\"90%\">\n"; echo "<tr>\n"; echo "<th>Event</th>\n"; echo "<th>Year</th>\n"; echo "<th>Team</th>\n"; echo "</tr>\n\n"; echo "<tr>\n"; echo "<td>$row[EventName]</td>\n"; echo "<td>$row[Year]</td>\n"; echo "<td>" . printf($link2, $row['EventName'], $row['Year']) . "</td>\n"; echo "</tr>\n"; echo "</table>\n"; Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 28, 2007 Share Posted August 28, 2007 Well, presumably all of the code you posted is in a loop similar to: while($row=mysql_fetch_assoc($result)){ //your code here } You should only place the echoing of the rows of the table inside the while loop. This is, afterall, the piece of code you want repeated. Overall, it would look something like: <?php $sql = "SELECT * FROM `yourtable`"; $result = mysql_query($sql); $num = mysql_num_rows($result); echo '<table><tr><td>Column1</td><td>Column2</td></tr>'; if($num > 0){ while($row = mysql_fetch_assoc($result)){ echo '<tr><td>'.$row['field1'].'</td><td>'.$row['field2'].'</td></tr>'; } }else{ echo '<tr><td colspan="2">No results found!</td></tr>'; } echo '</table>'; ?> This is just a rough example. You will, of course, need to modify this to work with your existing script. Quote Link to comment Share on other sites More sharing options...
Neptunus Maris Posted August 28, 2007 Share Posted August 28, 2007 Well, presumably all of the code you posted is in a loop similar to: while($row=mysql_fetch_assoc($result)){ //your code here } You should only place the echoing of the rows of the table inside the while loop. This is, afterall, the piece of code you want repeated. Overall, it would look something like: <?php $sql = "SELECT * FROM `yourtable`"; $result = mysql_query($sql); $num = mysql_num_rows($result); echo '<table><tr><td>Column1</td><td>Column2</td></tr>'; if($num > 0){ while($row = mysql_fetch_assoc($result)){ echo '<tr><td>'.$row['field1'].'</td><td>'.$row['field2'].'</td></tr>'; } }else{ echo '<tr><td colspan="2">No results found!</td></tr>'; } echo '</table>'; ?> This is just a rough example. You will, of course, need to modify this to work with your existing script. True I wasnt thinking about that part... Quote Link to comment Share on other sites More sharing options...
cheechm Posted August 28, 2007 Author Share Posted August 28, 2007 Sorry. Should have put full code: <?php $con = mysql_connect("sql3.byethost7.com","b7_463487","Junior007"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("b7_463487_LPS", $con); $link2 = '<a href="team.php?eventname=%s&year=%s" title="Team" rel="gb_page[422, 422]">Team</a>'; $result = mysql_query("SELECT * FROM results WHERE EventName='$_POST[eventname]' AND Result = 'None'"); while($row = mysql_fetch_array($result)) { echo "<table class=\"events\" width=\"90%\">"; echo "<tr>"; echo "<th>Event</th>"; echo "<th>Year</th>"; echo "<th>Team</th>"; echo "</tr>"; echo "<tr><td>"; echo "$row[EventName]"; echo "</td>"; echo "<td>"; echo "$row[Year]"; echo "</td>"; echo "<td>"; printf($link2, $row['EventName'], $row['Year']); echo "</td></tr>"; echo "</table>"; } mysql_close($con) ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 28, 2007 Share Posted August 28, 2007 Indeed. Read my last post - the solution is there. Quote Link to comment Share on other sites More sharing options...
cheechm Posted August 28, 2007 Author Share Posted August 28, 2007 OK thank you. I shall try it and then get back to you Quote Link to comment 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.