473,587 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Query Interface - HELP!

Hi,

I have been trying to build an custom report interface for a charity
manangement system; which is part of my dissertation. This interface
will allow the chairty to input a SQL query and submit the query. When
the submit button is executed, it will display the selected column names
and the query data. I am 80% finished but I have encountered a problem
though. I do not know how to display the dynamic column names?! Could
some please enlighten me as I feel like giving up! I can't find the
funtion/code I need!!!! HELP!!!!
Jul 17 '05 #1
2 2326
James Perry <2p******@solen t.ac.uk> writes:
I have been trying to build an custom report interface for a charity
manangement system; which is part of my dissertation. This interface
will allow the chairty to input a SQL query and submit the
query. When the submit button is executed, it will display the
selected column names and the query data. I am 80% finished but I
have encountered a problem though. I do not know how to display the
dynamic column names?! Could some please enlighten me as I feel like
giving up! I can't find the funtion/code I need!!!! HELP!!!!

May depend on what DB you are using...

I use Postgres and in the docs you will notice functions to get the
number of fields returned by a query and also functions to return the
field name for a numbered field.

Iterate over the field names once to build your table header and then
go on to output the rows/fields as needed.

Assuming the other DB APIs offer same functionality, but no guarantee.

HTH
--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 17 '05 #2
James Perry wrote:
I have been trying to build an custom report interface for a charity
manangement system; which is part of my dissertation. This interface
will allow the chairty to input a SQL query and submit the query. When
the submit button is executed, it will display the selected column names
and the query data. I am 80% finished but I have encountered a problem
though. I do not know how to display the dynamic column names?! Could
some please enlighten me as I feel like giving up! I can't find the
funtion/code I need!!!! HELP!!!!


This was my attempt when looking at some PEAR classes:

<?php

/**
* Short script for dumping stuff out of a database
*/

require_once 'HTML/Page.php';
require_once 'HTML/QuickForm.php';
require_once 'HTML/Table.php';
require_once 'DB.php';

$p = new HTML_Page();
$f = new HTML_QuickForm( 'irm_dumper');

$f->addElement('he ader',NULL,'Sub mit your query');
$f->addElement('te xt','query_stri ng','SQL Query (SELECT only)',
array('size' => 80));
$f->addElement('su bmit',NULL,'Que ry');
$f->addElement('re set',NULL,'Rese t query');

$p->addBodyContent ($f);

if ($_POST['query_string']) {

$dsn = array('phptype' => 'mysql',
'hostspec' => 'your.host.here ',
'username' => 'usr_name_here' ,
'password' => 'usr_passwd',
'database' => 'your_db_name') ;

$db =& DB::connect($ds n);

if (DB::isError($d b)) { die ($db->getMessage() ); }
else {

if (!preg_match("/^(UPDATE|INSERT )/i",$_POST['query_string'])) {

$query = stripslashes($_ POST['query_string']);

$sth =& $db->query($query );

if (DB::isError($s th)) {
$p->addBodyContent ("<p>ERROR<br>I nvalid SQL query!</p>");
$p->addBodyContent ("<p>" . $sth->getMessage() . "</p>");
}
else {
$t_attributes = array('rules' => 'all',
'frame' => 'border');

$t = new HTML_Table($t_a ttributes);

$db_header = $db->tableInfo($sth );

$headers = array();

foreach ($db_header as $c => $c_name) {
$headers = array_merge($he aders,array($c_ name['name']));
}

$header_attr = array('bgcolor' => 'steelblue');

$t->addRow($header s,$header_attr, 'TH');

$align_attr = array ('valign' => 'top');
for ($row=0; $row < $sth->numRows(); $row++) {
$t->addRow($sth->fetchRow(), $align_attr);
}

$light = array('bgcolor' => '#CCCCCC');
$dark = array('bgcolor' => '#AAAAAA');
$t->altRowAttribut es(1,$light,$da rk,TRUE);
$p->addBodyContent ($t);
}
}
else {
$p->addBodyContent ("<p>Sorry, only SELECT queries allowed!</p>");
}
}
}

$p->display();
?>
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2888
by: satish | last post by:
Hello all, I have a shared object executable viz. *cable* which I execute as follows : $ ansyscust71 -custom cable -p ANSYSRF **ansyscust71 is a shell script and is a part of a software called ANSYS** Now, I have generated a python module using a *fortran-python interface
1
6935
by: David | last post by:
Hi everyone. I have read every page that Google returns on this topic, but can't find anything that resolves my problem. Basically, I have an Access Database that does a number of different calculations. One of these calculations is rather complex, and could not be implemented properly using just nested IIF statements or anything similar,...
0
1881
by: Thomas D. | last post by:
Situation: --------------------------- I have an 'export'-wrapper to my regular objects. For each regular object there is also an export object. An export object derives from the regular object and has for each property in the base object an extra boolean property. That extra properties tells wether to include the base property in the final...
1
8472
by: Microsoft | last post by:
Hello there, I have following situation , how can I solve this puzzle in C#. I have interface called IVendor with some custom attributes applied to it interface IVendor {
21
2085
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a string with comma delimited values. For example, if I were to render two text boxes. One with the Value Terry and the Other with the Value 'Burns'...
3
1857
by: Shawn Ramirez | last post by:
As with most web applications speed is a huge deal to me in my applications. My customers don't really care if my app is a true 3 tier application or not, they just want it to be faster then it was yesterday. Because of this I try to limit my calls to the database by using a loading lookup data for a customer and then filtering down to what I...
14
14621
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control so I get the ObjectDataSource. No problem ..... ObjectDataSource src = .... //is ok i have it
0
903
by: Coolrah | last post by:
Hi to all, I am developing a Binder Manager which bind and unbind data from the webpage , i have almost completed the component with custom controls But i m facing one problem that i want to show in the collection editor of Binder Manager component only those controls which are custom controls (means made by me). My custom controls are...
6
2304
by: forest demon | last post by:
i have a custom control that gets loaded at runtime. i need to be able to access a property of a control thats part of the main form, through the clcik event of the custom control. i may be making this harder than it needs to be, but seem to be buffaloed at this point. thanks to all.... -
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.