Jump to content

[SOLVED] Showing query in table


cheechm

Recommended Posts

Hi,

I am trying to show the result of a query in a html table. So far I have this:

	<?php

$con = mysql_connect("");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("", $con);

$link = '<a href="review.php?event=%s&year=%d" title="Review" rel="gb_page[500, 500]">review</a>'; 

echo "<table class="results" width="420">";
echo "<tr><th>Event</th></tr>";
echo "<tr><th>Year/th></tr>";
echo "<tr><th>Result</th></tr>";
echo "<tr><th>Review</th></tr>";

$result = mysql_query("SELECT * FROM results");

while($row = mysql_fetch_array($result))
  {
  
echo "<tr><td>";
echo $row['EventName'];
echo "</td></tr>";
echo "<tr><td>";
echo $row['Year'];
echo "</td></tr>";
echo "<tr><td>";
echo $row['Result'];
echo "</td></tr>";
echo "<tr><td>";
printf($link, $row['EventName'], $row['Year']);
echo "</td></tr>";
}
echo "</table>";
  }  

mysql_close($con)

?>

 

At the moment it doesn't work. Does anyone have any ideas?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/
Share on other sites

The query is there:

 

$result = mysql_query("SELECT * FROM results");

while($row = mysql_fetch_array($result))
  {
  

 

unless I am not understanding right.

 

Yeah.. but there is absolutley no error checking. Something like...

 

<?php

  if ($result = mysql_query("SELECT * FROM results")) {
    if (mysql_num_rows($result)) {
      while($row = mysql_fetch_array($result)) {
        // show results.
      }
    } else {
      // no results found.
    }
  } else {
    // query failed.
  }

?>

 

is alot safer.

 

there aren't any errors in the MySQL coding. It is just the adding of the HTML table which stops the PHP displaying anything.

 

So what error checking should I put in. I don't have access to PHP.ini so I can't do something like

error_reporting  =  E_ALL

display_errors = On

What else can I do?

Archived

This topic is now archived and is closed to further replies.

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