0

How to display the records from the table by using the following source code?

Notice: Undefined offset: 0 in eval() (line 20 of /var/www/module(80) : eval()'d code).

<?php
include_once(drupal_get_path('module', 'webform').'/includes/webform.submissions.inc');
$query = db_select('webform_submitted_data', 'u');
$query->fields('u', array('sid','nid','data'));
$query->condition('nid','159','=');
$results =$query->execute();

echo "<table>";
echo "<tr>";
echo "<th>  Profile Photo </th>";
echo "<th> Faculty  Name and Department  </th>";
echo  "</tr>";

if ($record = $results->fetchAssoc())
{
$sid = $record['sid'];
$nid = $record['nid'];
$submission = webform_get_submission($nid,$sid);
echo "<tr>";
echo $val = $submission->data[15][0];
}
?>

3 Answers 3

1

Try below code,

You can retrieve node webform all submissions using webform_get_submissions which accepts an array of filters.. As per the error you mentioned in the question seems like below code is causing problem

echo $val = $submission->data[15][0];

I would suggest printing the information that you got before you try to fetch the data so that you know you are correclty accessing the array results.. print_r will assist you to see the results..

module_load_include('inc','webform','includes/webform.submissions');
$submissions = webform_get_submissions(array('nid'=> 159));

foreach ($submissions as $submission){
    foreach ($submission->data as $row=>$data){
        print '<pre>';print_r($row);print '</pre>';
        print '<pre>';print_r($data);print '</pre>';
    }
}

Extract the information you want from $row and $data ...

2
  • Hello. Would you mind adding some explanation to your code? Code-only answers tends to leave people clueless, even if it gets the job done for them/
    – Mołot
    Apr 18, 2014 at 12:45
  • Just updated the answer with details.. Thank you :-)
    – Anil Sagar
    Apr 18, 2014 at 12:51
0

On a sidenote, you should consider using theme_table to print a table, preferably using a renderable array ( as opposed to theme('table',.. ) ).

If you print everything manually, it's easy to forgot a tag, which might then completely screw up your layout :)

You can read more about theme_table here and renderable arrays here

0

Alternatively if you are planning on generating your own HMTL then use the following to view the data.

module_load_include('inc','webform','includes/webform.submissions');
$submissions = webform_get_submissions(1111);
krumo($submissions);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.