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:
  1. Create the function gfdf as shown below
  2. Query table formdata with SELECT *
  3. Get the value by calling gfdf as shown below
*PHP must be switched on in your u5CMS's config.php (there, look for "Where PHP code shall be executed")



[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";
$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]

Download

Content Management System u5CMS

Service

English⇄German Translation Service

Flowers

blumen-bern-maarsen.ch