[eluser]mlynno[/eluser]
Hi, I hope that I have picked the right forum for this. I'm new to PHP and CodeIgniter and working my way through the CodeIgniter 1.7 book trying to set up a CRUD function. I keep getting the message "Message: Undefined variable: query, Filename: models/crud_model.php,
Line Number: 56." Any advice would be greatly appreciated. BTW I am using CodeIgniter 1.7.3. Here is the code --
Model (applicable parts)
Code:
function get_record($PlantId)
{
if(!empty($PlantId))
{
$this->db->where('PlantId', $PlantId);
$query = $this->db->get('plantdata');
}
if ($query->num_rows() > 0) { // this is line 56 -- undefined $query
return $row = $query->row();
}
else
{
$row = FALSE;
}
return $row;
}
Here's the Controller (applicable parts)
Code:
function view_record($PlantId = '')
{
$this->load->model('crud_model');
$record = $this->crud_model->get_record($PlantId);
$data['title'] = "Record view: ";
$data['row'] = $record;
$this->load->view('crud/view', $data);
}
The view never gets called, but just in case, it looks like this (abbreviated):
Code:
<!DOCTYPE html>
<html>
<head>
<title>View Single Record</title>
</head>
<body>
<h1><?php echo $title ?></h1>
<?php
if($row == FALSE)
{
echo "The record does not exist";
}
else
{
?>
<ul>
<li>Plant ID: <?php echo $row->PlantId; ?></li>
<li>Plant Family: <?php echo $row->Family; ?></li>
...much more here ... </ul>
<?php
}
?>
</body>
My thanks in advance!