RE: [PHP-DB] Entering a Query
| From: | John W. Holmes | Date: | Wed, 02 Apr 2003 01:58:04 +0000 |
| Subject: | RE: [PHP-DB] Entering a Query | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26799@lists.php.net to get a copy of this message | ||
> I would be very interested to see an example of how it would be
possible
> to
> enter a query into a text area and the results of the query displayed
on
> the
> next page, similar to PHP admin I guess, are they any examples out
there?
Issue the query with mysql_query() and check for an error. If there's an
error, display mysql_error() or do your own error handling. From there,
you'll count the number of fields returned by mysql_num_fields(). Loop
through with mysql_field_name() to create your "header" row. The
"header" text will match whatever the name of the column was. Then loop
through mysql_fetch_row() to get all of the rows returned from the
query. You already know how many fields there are, so just loop through
the result of mysql_fetch_row() that many times and put each element in
it's own <td> tag.
That's pretty much it.
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/