Question
How to fetch data by searching multiple column in database at once? For example I have name, age and address. For now the code will
How to fetch data by searching multiple column in database at once? For example I have name, age and address.
For now the code will search any one of the column but cant find the data if I search all column 3 at once.
CODE
$con = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
if(isset($_POST["submit"])) { $search = $_POST["search"]; $sth = $con->prepare("SELECT * FROM tableuser WHERE name LIKE '%$search%' OR age LIKE '%$search%' OR address LIKE '%$search%' ");
$sth->setFetchMode(PDO:: FETCH_OBJ); $sth -> execute(); $result = $sth -> fetchAll();
if ($sth->rowCount()>0) { foreach($result as $row) { ?>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success