cheechm Posted June 4, 2007 Share Posted June 4, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/ Share on other sites More sharing options...
dough boy Posted June 4, 2007 Share Posted June 4, 2007 You should provide us with more information than just "It doesn't work". How do you know it doesn't? Are you getting an error message? If so what is it? Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/#findComment-267613 Share on other sites More sharing options...
cheechm Posted June 4, 2007 Author Share Posted June 4, 2007 The page doesn't display. Nothing shows. There is probably a problem somewhere, but I can't see one. Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/#findComment-267618 Share on other sites More sharing options...
trq Posted June 4, 2007 Share Posted June 4, 2007 Are you sure your query is actually returning results? You never check it before using it. Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/#findComment-267628 Share on other sites More sharing options...
dough boy Posted June 4, 2007 Share Posted June 4, 2007 This is also an invalid line. echo "<table class="results" width="420">"; "Should Be" echo "<table class=\"results\" width=\"420\">"; Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/#findComment-267629 Share on other sites More sharing options...
cheechm Posted June 4, 2007 Author Share Posted June 4, 2007 The query is returning results. I did ccheck to make sure. I will try what dough boy said. Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/#findComment-267633 Share on other sites More sharing options...
trq Posted June 4, 2007 Share Posted June 4, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/#findComment-267636 Share on other sites More sharing options...
cheechm Posted June 4, 2007 Author Share Posted June 4, 2007 The query is there: $result = mysql_query("SELECT * FROM results"); while($row = mysql_fetch_array($result)) { unless I am not understanding right. Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/#findComment-267641 Share on other sites More sharing options...
chigley Posted June 4, 2007 Share Posted June 4, 2007 $result = mysql_query("SELECT * FROM results") or die(mysql_error()); This will tell you any errors. Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/#findComment-267649 Share on other sites More sharing options...
trq Posted June 4, 2007 Share Posted June 4, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/#findComment-267653 Share on other sites More sharing options...
cheechm Posted June 4, 2007 Author Share Posted June 4, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/#findComment-267655 Share on other sites More sharing options...
trq Posted June 4, 2007 Share Posted June 4, 2007 I just showed you an example of how to catch errors. Also... any error reporting can be switched on and off using ini_set, but thats really besides the point. My code prevents errors all together. Quote Link to comment https://forums.phpfreaks.com/topic/54132-solved-showing-query-in-table/#findComment-267663 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.