php - Syntax error 1064 in SQL Query in selecting an id from database : Symfony -
i having error in sql query when try view profile of organiser:
sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near '' @ line 1
this controller function:
public function viewprofileaction(request $request) { $em = $this->getdoctrine()->getmanager(); $orgid = $this->getuser()->getid(); $clicknblog = $this->get('adventure_bridge.clicknblog'); $trails= $clicknblog->matchtrails($orgid); $clicknblog = $this->get('adventure_bridge.clicknblog'); $event= $clicknblog-> getevents($orgid); $user = $this->getuser(); $memberid = $user->getid(); $role = 'bidorganiser'; $organiserdetails = $em->getrepository('adventurebiddingbundle:bidorganiser')->getorganiserbymemberid($memberid,$role); foreach($organiserdetails $organiser){ $count= $organiser->getcountry(); $country = $clicknblog->getcountriesname($count); } //$countries = $clicknblog->getcountries(''); $organiser->setcountry($country); //redirecting user profile in view mode return $this->render('adventurebiddingbundle:organiser:viewprofileorganiser.html.twig',array( 'member' => $organiser, 'trails' => $trails, 'event'=> $event )); }
and service class function error is:
public function getcountriesname($id) { $stmt = $this->connection->query("select name countries id = $id"); // line having error $cid3 = $stmt->fetchall(pdo::fetch_assoc); foreach($cid3 $value){ foreach($value $country){ } } return $country;
}
what problem in sql syntax, if can resolve thank
change query -
"select `name` countries id = '$id'"
you using $country
outside loop. not accessible there. should -
foreach($cid3 $value){ foreach($value $country){ return $country; // } }
return
not let script execute whole loop. if want store in variable , return.
Comments
Post a Comment