本文整理汇总了PHP中Home::search方法的典型用法代码示例。如果您正苦于以下问题:PHP Home::search方法的具体用法?PHP Home::search怎么用?PHP Home::search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Home
的用法示例。
在下文中一共展示了Home::search方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
public function search($smarty, $tpl, $params, $DB)
{
$this->Test_session();
$res = new Home($DB);
if (isset($_POST['search'])) {
if (empty($_POST['search'])) {
$smarty->assign('errRecherche', "Votre recherche est vide !");
$this->Test_admin($smarty, $tpl, $params, $DB);
$this->init($smarty, $tpl, $params, $DB);
$smarty->display($tpl);
} else {
$recherche = $_POST['search'];
$tableau = explode(" ", $recherche);
$sql1 = 'SELECT * FROM posts';
$sql2 = 'SELECT * FROM posts';
$i = 0;
foreach ($tableau as $mot) {
if (strlen($mot) > 1) {
if ($i == 0) {
$sql1 .= ' WHERE ';
$sql2 .= ' WHERE ';
} else {
$sql1 .= ' OR ';
$sql2 .= ' OR ';
}
$sql1 .= ' textePosts LIKE "%$mot%"';
$sql2 .= ' titrePosts LIKE "%$mot%"';
$i++;
}
}
$sql1 .= ' ORDER BY idPosts DESC';
$sql2 .= ' ORDER BY idPosts DESC';
$r1 = $res->search($sql1);
$r2 = $res->search($sql2);
if ($r1) {
foreach ($r1 as $key => $value) {
if (!isset($tabP[$r1[$key]['idPosts']])) {
$tabP[$r1[$key]['idPosts']] = array();
}
array_push($tabP[$r1[$key]['idPosts']], html_entity_decode($r1[$key]['titrePosts']), $r1[$key]['datePosts'], $r1[$key]['membres_pseudoMbr'], $r1[$key]['catPosts_nomCatPosts']);
}
}
if ($r2) {
foreach ($r2 as $key => $value) {
if (!isset($tabP[$r2[$key]['idPosts']])) {
$tabP[$r2[$key]['idPosts']] = array();
}
array_push($tabP[$r2[$key]['idPosts']], html_entity_decode($r2[$key]['titrePosts']), $r2[$key]['datePosts'], $r2[$key]['membres_pseudoMbr'], $r2[$key]['catPosts_nomCatPosts']);
}
}
if (!$r1 && !$r2) {
$smarty->assign('errRecherche2', "Aucun résultat trouvé.");
$this->Test_admin($smarty, $tpl, $params, $DB);
$this->init($smarty, $tpl, $params, $DB);
$smarty->display($tpl);
} else {
$smarty->assign('postSearch', $tabP);
$this->Test_admin($smarty, $tpl, $params, $DB);
$this->init($smarty, $tpl, $params, $DB);
$smarty->display('home.tpl');
}
}
}
}