I need to get an array in this form:
array(':name'=>'PRIMO,':time_of_execution'=>12,':price'=>50,':active'=>1))
This is my start $cols array:
Array
(
[key] => Array
(
[0] => name
[1] => time_of_execution
[2] => price
[3] => active
)
[value] => Array
(
[0] => Array
(
[name] => PRIMO
[time_of_execution] => 10
[price] => 100
[active] => 1
)
)
)
In $cols['key'] I have the column of database and with this I can realize the base $sql:
$sql = 'INSERT INTO '.$this->table.'('.implode(",", $cols['key']).') VALUES (';
$i=1;
foreach ($cols['key'] as $key=>$value)
{
$sql.=':'.$value;
if ($i<count($cols['key']))
{
$sql.=', ';
}
$i++;
}
$sql.= ')';
Now last piece of code that I'm missing is transform the $cols['value'] in an array in this form:
array(':name'=>'PRIMO,':time_of_execution'=>12,':price'=>50,':active'=>1))
My code, but wrong is:
$max = count($cols['value']);
$i=0;
$k=0;
foreach ($cols['key'] as $key=>$value)
{
for($i=0;$i<$max;$i++)
{
$args[$k] = array(':'.$value=>$cols['value'][$i][$value]);
$k++;
}
}
mysql_*()function in OPs code and he is using parametrized queries!