would be a good project to help me learn cakePHP.
My "schedules" table has fields for hometeam, awayteam, homescore,
awayscore, and gamewinner. I created a model and controller based on
this table that can be called to update the gamewinner.
I can pull the data from the table but I am not sure how to save the
gamewinner field once it is calculated.
<?php
class UpdateschedulesController extends AppController {
var $name = 'Updateschedules';
function index() {
// Get all records from 'schedules' table using 'updateschedule'
model
$query = $this->Updateschedule->find('all');
// Move through each row to find game winner
// Ignoring the possibility of a tie for the moment
foreach ($query as $row)
{
if ($row["Updateschedule"]["awayteamscore"] >
$row["Updateschedule"]["hometeamscore"]) {
// awayteam is winner, update gamewinner field
with teamname
$row["Updateschedule"]["gamewinner"] =
$row["Updateschedule"]["awayteam"];
} else {
// hometeam is winner, update gamewinner field
with teamname
$row["Updateschedule"]["gamewinner"] =
$row["Updateschedule"]["hometeam"];
}
// New data will not save, it appears in the array if I use
print_r
$this->Updateschedule->save($row["Updateschedule"]);
}
// Send data to view to display updated data
// Does not display gamewinner
$this->set('schedules', $query);
}
}
?>
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
No comments:
Post a Comment