简体   繁体   中英

Getting select data from two tables where session id

I have a issue with a SELECT query. I'm basically trying to get information from two different tables, I want the customer information (orders) + the customers products (orders_products) and I only want the information for that specific ID.

Both tables have the user_id column.

$conn = new PDO('mysql:host='. DB_HOST .';dbname='. DB_NAME . ';charset=utf8', DB_USER, DB_PASS);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $conn->prepare("SELECT * FROM orders, orders_products WHERE `orders.user_id` = `orders_products.user_id` = :user_id");
$sth->bindValue(':user_id', $_GET['id']);
$sth->execute();
$result = $sth->fetch();
SELECT orders.*, orders_products.* FROM orders
JOIN orders_products on orders_products.user_id = orders.user_id
WHERE `orders.user_id` = :user_id;

Hope this help :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM