Last active
January 6, 2019 14:52
-
-
Save amirkhiz/5863acf11430e8941703fdfcb07d7cdd to your computer and use it in GitHub Desktop.
General Search in all tables of site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Controller { | |
public function search() | |
{ | |
$kelime = $_POST['query']; | |
$result = $this->site_model->search($keyword); | |
foreach ($result as $item) { | |
switch ($item->type) { | |
case 'products': | |
$item->id = site_url('products/' . $item->id); | |
break; | |
case 'posts': | |
$item->id = site_url('posts/' . $item->id); | |
break; | |
case 'services': | |
$item->id = site_url('services/' . $item->id); | |
break; | |
case 'articles': | |
$item->id = site_url('articles/' . $item->id); | |
break; | |
} | |
} | |
echo json_encode($result); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class Model { | |
public function search($keyword) | |
{ | |
$query = " | |
SELECT | |
id, | |
urun_adi AS ad, | |
'urun' AS type | |
FROM en_urunler | |
WHERE urun_adi LIKE ('%{$keyword}%') | |
UNION ALL | |
SELECT | |
id, | |
isim AS ad, | |
'sayfa' AS type | |
FROM en_sayfa | |
WHERE isim LIKE ('%{$keyword}%') | |
UNION ALL | |
SELECT | |
id, | |
isim AS ad, | |
'basinda' AS type | |
FROM en_basinda | |
WHERE isim LIKE ('%{$keyword}%') | |
"; | |
$result = $this->db->query($query)->result(); | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment