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) { ?> name; ?> age; ?> address; ?>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!