Jump to content

[SOLVED] Echoing Table


cheechm

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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)
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.