Created
December 18, 2018 16:08
-
-
Save lawrence254/48ddd8012d5b0a23481ef6b71cc18ad7 to your computer and use it in GitHub Desktop.
Search through stored data by cross-checking against saved phone numbers in the table to get all their transactions.
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 | |
if(isset($_GET['phone'])) | |
{ | |
$db_server = "localhost"; | |
$db_username = "username"; | |
$db_password = "password"; | |
$db_database = "dbName"; | |
$conn = new PDO("mysql:host=$db_server;dbname=$db_database", $db_username, $db_password); | |
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
$search_query=$_GET['phone']; | |
$sql = 'SELECT receipt,phonenumber,transday FROM transactions where MATCH(phonenumber) AGAINST(:search_query)'; | |
$statement = $conn->prepare($sql); | |
// echo $statement; | |
$statement->bindParam(':search_query', $search_query, PDO::PARAM_STR); | |
$statement->execute(); | |
if($statement->rowCount()) | |
{ | |
$row_all = $statement->fetchall(PDO::FETCH_ASSOC); | |
header('Content-type: application/json'); | |
echo json_encode($row_all); | |
} | |
elseif(!$statement->rowCount()) | |
{ | |
$error = "No Data Found For This User \n"; | |
header('Content-type: application/json'); | |
echo json_encode($error); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment