Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

2 The main characteristics of the market system.

Answered: 1 week ago