Ronan, thanks for the reference.
It took me a long time to create something very simplistic. At one time I tried to concatenate columns with a CASE expression and the got a collation error. So here is my code, albeit very unsatisfactory:
Code:
DROP PROCEDURE IF EXISTS html_table;
DELIMITER $$
CREATE PROCEDURE html_table(IN listOfColumns VARCHAR(100), tableName VARCHAR(100))
BEGIN
SET @query := CONCAT("SELECT CONCAT('<tr>', CONCAT('<td>', CONCAT_WS('</td><td>',", listOfColumns, "), '</td>'), '</tr>') htmlTableTags FROM ", tableName);
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END;
$$
It takes column names and the table name and executes an unconditional SELECT statement (no JOIN or WHERE). Test results are as follows:
Code:
mysql> delimiter ;
mysql> call html_table( "bookid, title", "books" );
+-----------------------------------------+
| htmlTableTags |
+-----------------------------------------+
| <tr><td>1</td><td>abc</td></tr> |
| <tr><td>2</td><td>photography</td></tr> |
| <tr><td>3</td><td>video</td></tr> |
| <tr><td>4</td><td>soccer</td></tr> |
| <tr><td>5</td><td>football</td></tr> |
| <tr><td>6</td><td>tennis</td></tr> |
| <tr><td>7</td><td>golf</td></tr> |
| <tr><td>8</td><td>fishing</td></tr> |
| <tr><td>9</td><td>cycling</td></tr> |
+-----------------------------------------+
9 rows in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Thanks again.