Re: displaying database output in a table

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

 



On Tue, May 25, 2010 at 9:27 PM, David Mehler <dave.mehler@xxxxxxxxx> 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);
>
> }
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Is that last part correct, or did you miscopy?  It appears there's no
opening bracket on this if:

if (!($result = @ mysql_query ($query, $db)))


Which would mean that only the next statement is impacted by the if.  And,
the next statement, which calls your displayEvents() function, is only
called if the query is unsuccessful.

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

[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