I am invoking the function in a package with the parameter as table name. After the execution of the sth,for the query built in such package, I want the resultset or by row-by-row in fetchrow_arrayref to be displayed in the caller function in a HTML table.
I have no idea of how to do this? Could someone help me out to solve this...
Ok, this is potentially an interesting problem, since we don't always know how many fields there are, or what there names are. We can solve this.
To do this, I used the following table:
Code:
# phpMyAdmin MySQL-Dump
# version 2.5.1
# http://www.phpmyadmin.net/ (download page)
#
# Host: localhost
# Generation Time: Jun 12, 2003 at 07:48 AM
# Server version: 3.23.56
# PHP Version: 4.2.2
# Database : `test`
# --------------------------------------------------------
#
# Table structure for table `mytable`
#
# Creation: Jun 12, 2003 at 06:41 AM
# Last update: Jun 12, 2003 at 06:42 AM
#
DROP TABLE IF EXISTS `mytable`;
CREATE TABLE `mytable` (
`id` int(10) unsigned NOT NULL auto_increment,
`petname` varchar(128) NOT NULL default '',
`species` varchar(20) NOT NULL default 'Dog',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=5 ;
#
# Dumping data for table `mytable`
#
INSERT INTO `mytable` (`id`, `petname`, `species`) VALUES (1, 'Jake', 'Dog'),
(2, 'Kitty', 'Cat'),
(3, 'Fred', 'Fish'),
(4, 'Peanut', 'Dog');
The Perl script I used is attached as a file ( see below somewhere ).
When you run the script, it will first ask to specify something for the where clause. This assumes we know at least one of the field names ( in this case, the species ). If you just press ENTER here, we will not use a WHERE clause.
The HTML output is in /tmp/index.html by default - you can change this in the code.
The code is a bit 'un-clean', so I belief there are still some optimising to do, but it should at least give you an idea.
I appreciate your response. But I would want the results to be returned back to the caller program wherein the results should be displayed in a table.
Will I be able to return the return the results from sqlexec to the invoker and then it is displayed in a table. If possible, how? The entire resultset or could I send it row by row?
Did you try the script? It does just that - returns the results in a table. If you read the internals, you will see it dumps the HTML file in /tmp/index.html