Hi guys i been trying to get this to work so it can generate the SQL statement to insert into the database , I think i have the output but i cant seem to work out how to retrieve each row from the multi-dimensional arrays.
The PHP code below along with the output.
function dataformat($_POST){
// The KEYS SENT BY POST IE THE FIELD NAMES.
$columns = array();
// The COrresponding VALUES FOR THE FIELDS.
$rows = array();
$i = 0;
foreach ($_POST as $key=>$value){
//Push the field name into the keys array
array_push($columns,$key);
array_push($rows,$value);
}
foreach($rows as $keys=>$values){
//create the array values
$values = explode("\r\n",$values);
echo "<br>";
print_r($values);
echo "<br>";
echo "<br>";
echo "Columns : ".count($columns)."<Br>";
echo "Values : ".count($values)."<br>";
echo "Rows : ".count($rows[1])."<br>";
echo "<br>";
echo $columns;
}
// Pop the 2 submits off of rows and columns.
array_pop($columns);
array_pop($rows);
}
The output from this code looks like this
Array ( [0] => Mr [1] => Miss [2] => Mr )
Columns : 5
Values : 3
Rows : 1
Array
Array ( [0] => Test [1] => Alice [2] => Joe )
Columns : 5
Values : 3
Rows : 1
Array
Array ( [0] => Admin [1] => Wonderland [2] => Bloggs )
Columns : 5
Values : 3
Rows : 1
Array
Array ( [0] => test@test.com [1] => alice@wonderland.com [2] => joe@bloggs.com )
Columns : 5
Values : 3
Rows : 1
Array
Array ( [0] => Submit )
Columns : 5
Values : 1
Rows : 1
Array
Now as you can see all the details for one user is in each array value ie..
Mr Test Admin has the Email test@test.com inside the [0] elements of each array.
and [1] is a new user
and element 2 is another users name and emails.
Ideally what i would like to achieve is a looped dynamic SQL which will take these elements and build an SQL statement to input them as seperate rows in the database.
Any help would be appreciated thanks 😉
Regards Shab