Help with query

if(isset($_GET["pdf"]) && isset($_GET["id"]) && isset($_GET["customer_name"]))
 require_once 'pdf.php';
 $output = '';
 $statement = $connect->prepare("
  SELECT * FROM payments 
  WHERE payment_id = :payment_id
  LIMIT 1;
  SELECT * FROM customers 
                 WHERE customer_name = :customer_name
				 LIMIT 1;");
   ':payment_id'       =>  $_GET["id"],
   ':customer_name'       =>  $_GET["customer_name"]
 $result = $statement->fetchAll();
 foreach($result as $row)

So I have 2 table payments and customer I want to be able to pull data from both but pull data from one table based on customer_name being the same in one table and the other and obviously store it in the same $row

If this is possible

You’d do that using a JOIN.


Is customer name the best (unique) way to identify someone? What happens if there are two customers in the table called “John Smith”?
An ID primary key would be a more robust solution, which you would probably reference as a foreign key in the payment table too.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.