Read a value of a field in datacsv of table formdata
Formdata entered in forms on u5CMS pages is stored as semicolon separated values in table formdata's column datacsv. The respective labels are stored in table formdata's column headcsv. To access the value(s) of a certain label with PHP*&SQL do the following:- Create the function gfdf as shown below
- Query table formdata with SELECT *
- Get the value by calling gfdf as shown below
[h:]
<?php
function gfdf($fieldname,$headcsv,$datacsv) {
$headcsv=explode(';',$headcsv);
array_walk($headcsv,'subone');
$datacsv=explode(';',$datacsv);
array_walk($datacsv,'subone');
$position=array_search($fieldname,$headcsv);
return str_replace(',.',';',$datacsv[$position]);
}
$sql_a="SELECT * FROM formdata WHERE formname='herecomesthenameoftheform' AND status=1";$headcsv=explode(';',$headcsv);
array_walk($headcsv,'subone');
$datacsv=explode(';',$datacsv);
array_walk($datacsv,'subone');
$position=array_search($fieldname,$headcsv);
return str_replace(',.',';',$datacsv[$position]);
}
$result_a=mysql_query($sql_a);
if ($result_a==false) echo 'SQL_a-Query did not work!<p>'.mysql_error().'<p><font color=red>'.$sql_a.'</font><p>';
$num_a = mysql_num_rows($result_a);
for ($i_a=0; $i_a<$num_a; $i_a++) {
$row_a = mysql_fetch_array($result_a);
$thevalue=gfdf('herecomesthenameofthefield',$row_a['headcsv'],$row_a['datacsv']);
echo $thevalue;
}
?>
[:h]