I have an array like below.
Where i need to insert all the values of ActionKey
and ActionValue
corresponding to each index for the same AdId
ie)
0th index - sms - 213123 and
1st index call - 12313
I am trying something like, but not working out.
$sDate = date("Y-m-d H:i:s");
$values = array();
$d_actionKey = $this->params()->fromPost('d_ActionKey');
$d_actionValue = $this->params()->fromPost('d_ActionValue');
$sql = "INSERT INTO `AdActions` (`CreatedDate`,`ActionKey`,`ActionValue`) VALUES";
foreach($values as $value) {
$values[] = "($sDate, $d_actionKey, $d_actionValue)";
}
My table data should look like.
UPDATED CODE:
I need to get the AdId from another table's last inserted value. Then take that last inserted AdId and insert into AdActions
$adActionsInsert = $this->getAdLibraryTable()->saveAdd($dataArray);
$query='INSERT INTO `AdActions` (`AdId`,`CreatedDate`,`ActionKey`,`ActionValue`) VALUES ';
for($i=0; $i < count($adActionsArray['ActionKey']); $i++)
{
if($i!=0)
$query .= ', ';
$query .= sprintf("(%d,'%s', '%s', '%d')",
$adActionsInsert,
$adActionsArray['CreatedDate'],
$adActionsArray['ActionKey'][$i],
$adActionsArray['ActionValue'][$i]);
}
I am able to get the last insert value like below (from the model file)
$this->tableGateway->lastInsertValue;