[email protected] wrote:
> Before most of you go on a rampage of how to please read below...
>
> As most of you already know when using MySQL from the shell you can write
> your queries in html format in an out file.
>
> Example: shell>mysql -uyourmom -plovesme --html
> This now will return all results in an html format from all queries.
>
> Now I could “tee” this to a file and save the results returned if I so choose
> to save the result of the display .
>
> Let’s say I want to be lazy and write a php MySQL query to do the same so
> that any result I queried for would return the html results in a table
> without actually writing the table tags in the results.
>
> Is there a mysql_connect or select_db or mysql_query tag option to do that
> since mysql can display it from the shell?
>
Here is my rendition of an result to HTML table output function.
This is normally used within my db class
but I have modified it to work with a MySQLi result object
function debug($result) {
/* get column metadata */
$html = '<table border="1"><tr>';
foreach ( $result->fetch_fields() AS $val ) {
$html .= '<th>'.$val->name.'</th>';
}
$html .= '</tr>';
foreach ( $result->fetch_row() AS $row ) {
$html .= '<tr>';
foreach ( $row AS $value ) {
$html .= '<td> '.$value.'</td>';
}
$html .= '</tr>';
}
$html .= '</table>';
return $html;
}
Let us know if that works for you.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php