Then to use the custom method:
<?php
$dao = new VehicleDAO();
$volist = $dao->findByPrice(5000, "<");
foreach($volist as $vo)
{
echo($vo->getDescriptiion() . "<br />");
}
?>
The above would produce a list of Ford vehicles whose price was less than $5000.
The data manipulation methods are simple and use VO objects to add, update or remove data.
- function insertVO($vo) –
- Inserts the data from a VehicleVO into the database. Returns the number of rows affected.
- function updateVO($vo) –
- Updates a record based on the value of $vo->vehicleid. Returns the number of rows affected.
- function deleteVO($vo) –
- Deletes a record based on the value of $vo->vehicleid. Returns the number of rows affected.
Putting It All Together
In applist.php, we create a list of vehicles and display them to the user.
<?php
$dao = new VehicleDAO();
$volist = $dao->findWhere("", "make, year LIMIT 0, 25");
foreach($volist as $vo)
{
echo("<tr><td><a href='appedit.php?vid=$vo->vehicleid'>$vo->vehicleid</a></td>");
echo("<td>$vo->make</td><td>$vo->year</td><td>$vo->model</td>
<td>$vo->color</td></tr>");
}
...
?>
Clicking on the vehicle id link takes the user to the vehicle_edit.php page.