/** * Print search results for a given search string. * @param $searchString * @param $limit * @param $page * @param $viewAll */ function printSearchResults($searchString, $limit = 0, $page = 0, $viewAll = 0) { global $dbi, $login; $result = $dbi->query("SELECT id,MATCH(name) AGAINST ('{$searchString}' IN BOOLEAN MODE) AS score FROM " . contributorTableName . " WHERE MATCH(name) AGAINST ('{$searchString}' IN BOOLEAN MODE) ORDER BY name" . (!empty($limit) && $viewAll ? " LIMIT " . $limit * $page . "," . $limit : (!empty($limit) ? " LIMIT " . $limit : ""))); if ($result->rows()) { $highlight = str_replace("\"", "", stripslashes($searchString)); for ($i = 0; list($id, $score) = $result->fetchrow_array(); $i++) { $contributor = new Contributor($id); printSearchResultItem($searchString, $contributor->name, "Ingen beskrivelse.", $contributor->getLink($id), $score); } } $result->finish(); }
public static function read($id) { global $db; if ($db) { $query = $db->prepare('SELECT * FROM `contributor` WHERE id = ?'); $query->execute(array($id)); if ($item = $query->fetch()) { $contributor = new Contributor($item[`name`], $item[`born`], $item[`died`]); $contributor->setID($item[`id`]); return $contributor; } } return false; }
<?php require_once 'config.php'; require_once 'contributor.php'; if (isset($_POST['submit'])) { $contributor = new Contributor($_POST['name'], ['birth'], ['death']); $contributor->create(); } ?> <html> <head> <title>Composers of Film Music</title> </head> <body> <form method="POST" action=""> Enter the name of the composer: <input type="text" name="name"></input><br /> Enter the date the composer was born: <input type="text" name="birth"></input><br /> Enter the date the composer died, if applicable: <input type="text" name="death"></input><br /> <input type="submit" name="submit" value="submit"></input><br /> </form> <?php if (isset($Contributor)) {
/** * A validation callback for making sure email addresses aren't re-used * @param string $email * @return bool */ public function email_check($email) { $this->load->model('contributor'); $this->load->library('form_validation'); if (!Contributor::findByEmail($email)) { return true; } $this->form_validation->set_message('email_check', 'This email has already been used'); return FALSE; }