Created
January 22, 2018 02:03
-
-
Save julianjupiter/dae9c8d185eb5614b4720a4fdcc31e95 to your computer and use it in GitHub Desktop.
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
<?php | |
function sql($terms) | |
{ | |
$q = "SELECT * FROM table1 WHERE "; | |
$i = 0; | |
foreach ($terms as $each) | |
{ | |
$i++; | |
if ($i == 1) | |
{ | |
$q .= "name LIKE '%$each%' "; | |
} | |
else | |
{ | |
$q .= "OR name LIKE '%$each%'"; | |
} | |
} | |
return $q; | |
} | |
$connection = mysqli_connect("localhost", "root", "admin", "jtest"); | |
$search = isset($_GET['search']) ? $_GET['search'] : ''; | |
if (empty($search)) | |
{ | |
echo 'Walang laman si get'; | |
} | |
else | |
{ | |
$terms = explode(' ', $search); | |
$q = sql($terms); | |
$query = mysqli_query($connection, $q); | |
$count = mysqli_num_rows($query); | |
if ($count > 0) | |
{ | |
while ($row = mysqli_fetch_assoc($query)) | |
{ | |
echo $row["name"] . "<br>"; | |
} | |
} | |
else | |
{ | |
echo "No result"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment