Jump to content

Outputting MySQL as plain text on a webpage


Eiolon

Recommended Posts

Is it possible to output results from a MySQL query using PHP as plain text onto a webpage so there is no need for rows?  For example, I run a command in the MySQL commandline and it will output the rows for me.

 

mysql> SELECT COUNT(r.report_category) AS TOTAL, c.category_name AS CATEGORY FROM reports r JOIN categories c ON (report_category = category_id) WHERE report_added BETWEEN '2009-01-01' AND '2009-12-31' GROUP BY category_name

+-------+--------------------------------------+
| TOTAL | CATEGORY                             |
+-------+--------------------------------------+
|    16 | BICYCLE THEFT(S)                     |
|     5 | CRIMINAL ACTIVITY                    |
|     9 | DISRESPECT TO STAFF          |
|     4 | INAPPROPRIATE/FOUL LANGUAGE          |
|     7 | MEDICAL ASSISTANCE                   |
|     6 | MISUSE OF EQUIPMENT/PROPERTY |
|    13 | NOT SPECIFIED                        |
|     7 | PATRON ASSISTANCE                    |
|    19 | POLICY VIOLATION(S)                  |
|     1 | SUSPICIOUS ACTIVITY                  |
|    16 | THEFT OF PROPERTY            |
|     9 | UNATTENDED CHILD                     |
|    51 | UNRULY / DISRUPTIVE BEHAVIOR         |
|     6 | VEHICLE ACCIDENT                     |
|     3 | VEHICLE RELATED INCIDENT             |
|     1 | VIEWING PORNOGRAPHIC MATERIAL(S)     |
+-------+--------------------------------------+
16 rows in set (0.00 sec)

 

I was curious if I can have the same affect or do I always need to use rows for displaying it on a webpage?

If I used the above in a typical query, it would like like this:

 

$query = " SELECT COUNT(r.report_category), c.category_name FROM reports r JOIN categories c ON (report_category = category_id) WHERE report_added BETWEEN '2009-01-01' AND '2009-12-31' GROUP BY category_name";
$result = mysql_query($query) OR die ('Cannot retrieve a list of reports.');
$row = mysql_fetch_array ($result);

 

Then I would echo $row in a table to display data.  That is fine, and I can do that, but I was looking for something similar to how the CLI outputs the data.  I was just curious if that was possible or not.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.