Are you looking for an exciting career in the world of cyclery? Look no further!
" : "entries.
"); overview_start(); for($i = 1; $i <= $nr; $i++) { overview_entry(unserialize($matches[$i])); } overview_end(); }
The function commences by opening the database in read mode, returning from the function if dba_open() failed. Otherwise, it performs the search using our helper function search_keyword(). The matches found by that function are stored in the array $matches. Since we do not need the database anymore, we close it using dba_close(). After printing out a short sentence indicating the number of matches found, we use our previously built overview system to create the overview. Beginning with overview_start(), we call overview_entry() for each entry in the $matches array, and finalize that by calling overview_end().
Deleting an Entry A database without the capability to delete entries is not very useful for real applications. So, our address book should also allow us to delete entries. The function to accomplish this, action_delete(), can be accessed through the overview form. It takes the ID for the entry to be deleted as its parameter. In this function, we open the database in write mode, return from the function if dba_open() failed and delete the entry with the ID which was passed into the function. A success message is also printed to inform the user that the action has taken place and the entry has successfully been deleted. After that, we save the change with the dba_sync() function; this takes the database handle as its argument. Finally, we close the database: function action_delete($id) { global $dbpath, $dbtype;
TEAM FLY PRESENTS
$db = dba_open($dbpath, "w", $dbtype); if(!$db) { echo("Database open failed"); return; } dba_delete($id, $db); echo("Entry $id successfully deleted"); dba_sync($db); dba_close($db); }
This could (and probably should) be extended to ask the user whether he or she really wants to delete a specific entry, before the real deletion is performed. Another protective measure would be never to delete the real entry, but to maintain the state for each entry. This state could be changed to "delete", so that we can recover all information, should a user do something wrong.
Displaying an Entry We also need a function for displaying individual entries. This function, display_entry(), takes an array of data which contains the information for the whole entry. The function consists mainly of HTML and some PHP commands which print out information from the $data array: Name: echo($data["name"]); ?>