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
Share on other sites

I did ccheck to make sure.

 

Then why remove it from your code (or did you do it some other way?). Its always best to check your queries are valid and hold results (through code) before you start trying to loop through them.

Link to comment
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.

 

Link to comment
Share on other sites

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?

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.