0

I'm trying to create a products based website that a user clicks through from one page which brings up a category and then splits into different applications for each product. I have have come across an initial stumbling block as I cannot get the page to display anything when trying to join my products and category tables together.

I've tried looking around for code samples to try, but as being rather new to PHP and PDO i'm struggling to understand things in simple terms.

Here's my current join which according to PMA works as it should. Any ideas how I make that statement an array I can foreach through?

if (isset($_GET['id'])) {
    $id = $_GET['id'];

    $data = $category->fetch_data($id);

    $query = $pdo->prepare('SELECT * FROM products LEFT JOIN category on products.prod_category = category.cat_name WHERE category.cat_id=?');
    $query->bindValue(1, $data);
    $query->execute();

    $products = $query;


}
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Chris Ware
  • 105
  • 1
  • 7
  • You are trying to do many things at once. Namely using PHP, GET, PDO and SQL, and you have no idea in which part it fails. Start from simple things. Forget about PHP for a time and make yourself familiar with SQL. Write all your queries in mysql console/phpmyadmin and make sure they return what you want. Only then try to run them from PHP using PDO – Your Common Sense May 14 '19 at 11:42
  • Thanks for that. I have tested this query through PMA SELECT * FROM products INNER JOIN category on products.prod_category = category.cat_name WHERE category.cat_id ='7' which seems to return a result as expected. However, I am struggling to convert to PDO. Currently I have the following... – Chris Ware May 14 '19 at 12:11
  • ill just edit the original question... – Chris Ware May 14 '19 at 12:13
  • Here you can find PDO examples: https://phpdelusions.net/pdo_examples/select#prepare – Your Common Sense May 14 '19 at 12:26

0 Answers0