Thursday, March 31, 2011

execute query twice in a short time is a problem?

I have a problem saving model in a loop. I am not sure the problem is
executing
a query twice in such a short time or how I am calling is the problem.
I tried with $this -> controller -> Notification -> save but didn't
work so i am trying to do with
maunally query instead but still get the same result. only the first
get saved but not the second one.


foreach( $arrEmp as $employeeObj ){
$options = array( "survey_name" => $surveyObj[ 0 ][ 'Survey' ]
[ 'survey_name' ] );
$this -> Notification -> create( 'Report card is realeased','',
$currentUser[ 'Account' ][ 'id' ], $employeeObj[ 'e' ]
[ 'accounts_id' ], 7, "HR Department", $options );
}

/**
* create function in Notification Component
*/
function create( $subject, $message="", $creator, $recepient, $type =
0, $from, $options=null ){
$this -> controller -> loadModel('Notification');
$this -> controller -> Notification -> create();
$notification[ 'subject' ] = htmlentities( $subject );
$notification[ 'message' ] = htmlentities( $message ) .
$defaultMessage;
$notification[ 'from' ] = htmlentities( $from );
$notification[ 'creator' ] = $creator;
$notification[ 'sentto' ] = $recepient;
$notification[ 'type' ] = $type;

foreach( $notification as $key => $value ){
$arrKey[] = $key;
$arrValues[] = $value;
}

$sql .= "INSERT INTO notifications (" . implode( ",", $arrKey ) . ")
values (" . implode( "," , $arrValues ) . " )";
$this -> controller -> Notification -> Query( $sql );
}

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate