how to fetch webform records from table by using drupal db_select i want to display the output in the following format by using the following source code but the following source code shows error 


  Notice: Undefined offset: 0 in eval() (line 20 of /....----modules/php/php.module(80) : eval()'d code).




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

echo "&lt;table&gt;";
echo "&lt;tr&gt;";
echo "&lt;th&gt;  Profile Photo &lt;/th&gt;";
echo "&lt;th&gt; Faculty  Name and Department  &lt;/th&gt;";
echo  "&lt;/tr&gt;";

if($record = $results-&gt;fetchAssoc())
{
$sid = $record['sid'];
$nid = $record['nid'];
$submission = webform_get_submission($nid,$sid);
echo "&lt;tr&gt;";
$val = $submission-&gt;data[15][0];

$query1 = db_select('file_managed', 'u');
$query1-&gt;fields('u', array('fid','filename'));
$query1-&gt;condition('fid',$val,'=');
$results1 =$query1-&gt;execute();

if ($record1 = $results1-&gt;fetchAssoc())
{
$path = $record1['filename'];


echo "&lt;td&gt; &lt;a href ='http://../content/detailed-information/?val=$sid'  target='_blank'&gt;&lt;img src ='../profile/$path'   width = '100' height='100' /&gt; &lt;/a&gt; &lt;/td&gt;";
}
echo "&lt;td&gt;&lt;b&gt;" .  "Name : " . $submission-&gt;data[1][0] . "&lt;/b&gt;&lt;br&gt;" .  " Designation : " . $submission-&gt;data[2][0] . "&lt;br&gt;" . " Department : " . $submission-&gt;data[3][0] ."&lt;br&gt;" . " E-mail : " . $submission-&gt;data[4][0] .  "&lt;/td&gt;"; 
echo "&lt;/tr&gt;";
}
echo "&lt;/table&gt;";

?&gt;
Just as it says, the error is in the line

$val = $submission-&gt;data[15][0];


so the variable $submission-&gt;data[15] does not contain a value [0]. Most likely the array is empty.

Of course, it's probably a bad idea to go to the database yourself, rather than using Webforms API functions. A little searching can get you started.