Eiolon Posted August 20, 2009 Share Posted August 20, 2009 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? Link to comment https://forums.phpfreaks.com/topic/171220-outputting-mysql-as-plain-text-on-a-webpage/ Share on other sites More sharing options...
corbin Posted August 20, 2009 Share Posted August 20, 2009 The MySQL CLI is what formats that. That's not the format the MySQL server sends data in or anything. What exactly do you mean without rows? Link to comment https://forums.phpfreaks.com/topic/171220-outputting-mysql-as-plain-text-on-a-webpage/#findComment-902929 Share on other sites More sharing options...
Eiolon Posted August 20, 2009 Author Share Posted August 20, 2009 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. Link to comment https://forums.phpfreaks.com/topic/171220-outputting-mysql-as-plain-text-on-a-webpage/#findComment-902939 Share on other sites More sharing options...
corbin Posted August 21, 2009 Share Posted August 21, 2009 I'm sure you could code a simple function that could do that automatically or something. Link to comment https://forums.phpfreaks.com/topic/171220-outputting-mysql-as-plain-text-on-a-webpage/#findComment-902994 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.