With the way it's stored it's going to be difficult to get the data out of the database as an associative array. It might be better to get the data out of the database, then create the array with PHP.
One possible way to do it is like this:
Code:
<?php
// Get all the rows
$query = 'SELECT ff_name, value, pid FROM tl_formdata_details';
$result = mysql_query($query);
// Loop through the result
while($row = mysql_fetch_array($result))
{
// If it's a name field assign the value to the 'firstname' key of our array
if($row['ff_name'] == 'firstname')
{
// Use the PID as the main array key so that the right username and email are grouped together
$arrData[ $row['pid'] ]['firstname'] = $row['value'];
}
// If it's an email field assign it to the email key of the array
if($row['ff_name'] == 'email')
{
// Use the PID as the main array key so that the right username and email are grouped together
$arrData[ $row['pid'] ]['email'] = $row['value'];
}
}
?>
$arrData data is now an associative array that looks something like this:
Code:
array(
[5] => array('firstname' => 'Jim', 'email' => 'jim@email.com'),
[3] => array('firstname' => 'Bill', 'email' => 'billy@email.com'),
[8] => array('firstname' => 'Sally', 'email' => 'sally@email.com')
);
The number being the PID. Also if you're doing this inside of Contao you'd be much better off using the Database class (http://api.contao.org/v3/classes/Contao.Database.html) to run your query than mysql functions.
Maybe someone knows how to do this directly with SQL, but this is how I'd try it.
Bookmarks