Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

How to display query results on a form?

Post Reply
bluemoon4281
Posts: 4
Joined: Thu Apr 19, 2012 1:02 pm

How to display query results on a form?

Unread post by bluemoon4281 »

Hi everyone,
I want to display the results of a query, preferably as a HTML table, on a form. The form's first tab shows the parent record and the subsequent tabs show the child records from different tables. I thought I could do this with PHP in a HTML object however PHP is only executed in reports. I want to display a non-editable overview of the records in the child tables, so all the information is available on one screen without having to browse through many tabs (e.g. to show a table showing addresses, phone numbers and email addresses). This will probably be based on a view comprised of many unioned queries.

I have tried to do this with a subform, but this takes up much more onscreen space and cannot easily include icons/images.

Thanks,
James
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: How to display query results on a form?

Unread post by admin »

bluemoon,

try this..


//-- Create a nuBuilder html object that contains this..

Code: Select all

<div id='HTMLobject' style='top:10px;left:10px;width:400px;height:400px'></div>
this goes in 'Before Open' of the form

Code: Select all


$HTMLstring       = '';
//-- add table name
$table           = '';
$result          = nuRunQuery("SELECT * FROM $table");
$fields_num      = db_num_fields($result);


$HTMLstring      .= "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++){
    $field       = db_fetch_field($result);
    $HTMLstring  .= "<td>{$field->name}</td>";
}
$HTMLstring      .= "</tr>\n";
// printing table rows
while($row = db_fetch_row($result)){

    $HTMLstring  .= "<tr>";
    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell){
        $HTMLstring .= "<td>$cell</td>";
	}

    $HTMLstring .= "</tr>\n";
}

$HTMLstring .= "</table>\n";


$HTMLstring = base64_encode($HTMLstring);

$jsString  = "function nuLoadThis(){\n";
$jsString .= "   var nuHTMLtable = '$HTMLstring';\n";
$jsString .= "   document.getElementById('HTMLobject').innerHTML = decode64(nuHTMLtable);\n";
$jsString .= "}";


addJSFunction($jsString);

It builds the table with php into a string and then inserts it into a div as the page is loaded.



Steven
Post Reply