1

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();
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Tweath
  • 99
  • 9
  • 1
    I think you want to start look into `JOIN`. See here: http://dev.mysql.com/doc/refman/5.6/en/join.html Also to understand what the different joins do, this is a really good question: http://stackoverflow.com/q/5706437/3933332 – Rizier123 Feb 01 '15 at 02:48
  • Thanks worked great with help from SQLfiddle @Rizier123 – Tweath Feb 01 '15 at 03:01
  • Cool that you could figure it out yourself! (BTW: You can answer your own question if you want and share it with everyone (+You also can accept your own answer), you also can delete your question. But the decision is yours what you do with your question, just wanted to show you different ways/possible things you can do) – Rizier123 Feb 01 '15 at 03:03

1 Answers1

0
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 :)

Siniseus
  • 121
  • 6