Re: displaying database output in a table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2010-05-25 at 21:27 -0400, David Mehler wrote:

> Hello,
> I'm trying to display mysql database output in a formatted table. My
> problem is i'm getting a blank screen with no errors. I've got
> debugging on, and have run the cli php on this file which produces no
> errors either, but neither does it give me any output.
> My eventual goal is to select the two nearest future events to the
> current date. Having done that I want to display the name, location,
> start date, start time, and a summary. Right now though I just want to
> put all information in the database in to a table.
> 
> Here's the code. Pointers welcome.
> Thanks.
> Dave.
> 
> <?php
> require_once($_SERVER['DOCUMENT_ROOT'] . "/dbconnect.php");
> 
> function displayEvents($result) {
> echo "<h2>Two Next Upcoming Events.</h2>\n";
> ?>
> 
> <table border=1 cellpadding="5" cellspacing="1">
> <tr>
> <th>Event Location.</th>
> <th>Event Summary</th>
> <th>Event Time</th>
> </tr>
> 
> <?php
>      while ($row = @ mysql_fetch_row($result))
> {
>         echo "\n<tr>";
>         foreach($row as $data)
>            echo "\n\t<td> $data </td>";
>         echo "\n</tr>";
>      }
> ?>
> </table>
> 
> <?php
> $query = "SELECT * FROM events";
> 
>   if (!($result = @ mysql_query ($query, $db)))
> 
> displayEvents($result);
> mysql_close($db);
> 
> }
> ?>
> 


How have you turned on the error reporting (I assume you meant that and
not debugging, which is quite different) If you've turned it on from
within PHP, then a fatal error could well result in a blank screen. Try
turning the display_errors on in the .htaccess, or preferably the
php.ini file. If you can't, then just take a look at the raw logs
(usually kept in /var/logs)

Also, I'm not sure you can use $_SERVER['DOCUMENT_ROOT'] in a cli
script, as I believe the $_SERVER is only set when PHP is running in a
web server. Are you sure that this is being correctly populated by your
server and that it is attempting to pull in the file correctly?

If the file is being pulled in correctly, is it connecting to the
database?

I would try to avoid jumping in and out of PHP code whilst inside a
function or loop, as it can lead to hard to read code. As it's very
simple html output you're after, have you considered using heredoc or
nowdoc syntax for it? You won't have to break out of PHP for a few lines
of output, and you can keep code nicely formatted and easy to read.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux