Dhanpal N
asked on
How to get only the search result?
<?php
//Step1
$db = mysqli_connect('localhost','username','','db_name')
or die('Error connecting to MySQL server.');
?>
<html>
<head>
</head>
<body>
<h1>PHP connect to MySQL</h1>
<?php
//Step2
$query = "SELECT * FROM imabangalore";
mysqli_query($db, $query) or die('Error querying database.');
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
while ($row = mysqli_fetch_array($result)) {
echo $row['Name'] . ' ' . $row['IMA Memb No'] . ' ' . $row['Spouse Name'] . ' ' . '<br />';
}
mysqli_close($db);
?>
</body>
</html>
Results shows all the data, but I want only the searched Name and their details
Results shows all the data, but I want only the searched Name and their detailsSearch based on ...?
If you want to filter your query you do it like this
$query = "SELECT * FROM imabangalore WHERE `Name`='{$searchvalue}'";
Where searchvalue comes from depends on your application - it might be sent to the page as a POST or a GET
www.yourdomain.com/yourpage.php?Name=John
In which case you could add this line to the start of your code to get the value from the URL
$searchvalue = isset($_GET['Name']) ? $_GET['Name'] : '';
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
$query = "SELECT * FROM imabangalore WHERE 'Name'=some search name you want";