This question is an exact duplicate of:
https://drive.google.com/file/d/0ByVhijs7bMwjUUZQRHpXUHFvODg/edit?usp=sharing
this s my code
i cant select the product_name and price form two tables"herbs" and "fruits" by using UNION i am a very beginner of php and mysql please help me
$results = $mysqli->query("SELECT * FROM fruits UNION SELECT * FROM herbs WHERE product_code='$product_code' LIMIT 1");
$obj = $results->fetch_object();
</div>
I would advise you to read this tutorial first. The where
keyword should be used for each table. Like this:
$results = $mysqli->query("SELECT * FROM fruits WHERE product_code='$product_code' UNION SELECT * FROM herbs WHERE product_code='$product_code' LIMIT 1");
$obj = $results->fetch_object();
try this
$results = $mysqli->query("
SELECT * FROM fruits WHERE t.product_code='$product_code'
UNION
SELECT * FROM herbs WHERE t.product_code='$product_code'
LIMIT 1");
$obj = $results->fetch_object();