I'm currently developing a module for Drupal 6 to output my webform entries to a table that can be filtered and searched.
I've got an AJAX callback function that returns my sql query but I can't figure out how to add line breaks as the data from each form field is in different rows in the database as per the webform module.
This is my callback function so far
function web_form_table_get_table($arg1){
$query = "SELECT nid, sid, cid, no, data " .
"FROM webform_submitted_data " .
"ORDER BY sid desc, cid, no";
$queryResult = db_query($query);
while ($webformTable = db_fetch_object($queryResult)) {
$items .= '<td>' . $webformTable->data . '</td>' ;
}
if ($items == '') {
$items = "Your search yeilded no results.";
}
return drupal_json(array('products'=>$items));
exit;
}
I've attempted to add some if statements to check if 'sid' (form reference) has changed and if so to add a line break but this just causes the site to crash.
My jquery is as follows:
// $Id$
Drupal.behaviors.web_form_table = function (context) {
$('a.getTable:not(.getTable-processed)', context).click(function () {
var updateProducts = function(data) {
$('#divProducts').html(data.products);
}
$.ajax({
type: 'POST',
url: this.href,
success: updateProducts,
dataType: 'json',
data: 'partNo=' + document.getElementById("partNo").value +
'&worksNo=' + document.getElementById("worksNo").value +
'&serialNo=' + document.getElementById("serialNo").value +
'&transType=' + document.getElementById("transType").value
});
return false;
}).addClass('getTable-processed');
}
Has anyone got any ideas on how this should be done?
Help! Thanks.