I write doctrine update query in symfony but it always takes last data and put it in all the fields, here is my code:
if($request->isXmlHttpRequest()) {
$response = new Response();
for($i=0; $i<$sectioncounter; $i++){
$sectionname = $_POST['sectionName'.$i];
$description=$_POST['description'.$i];
$query = $em->createQuery("Update ProposalsProposalsBundle:Sections s set s.sectionName='".$sectionname."',s.description='".$description."',s.updatedDatetime='".$date."' where s.proposalID='".$proposalid."'");
$ids = $query->getResult();
}
return $response;
}
My sectioncounter=2
but when I check in database $description1,$sectionname1
values overwrite $sectionname0
and description0, how to remove this error? I want update query to run sectioncounter
times, how do I do this?
Where do you change the value of $proposalid? If you dont change this you are executing this query many times afecting the same row