如何从两个调用表(函数)中获取数据两次使用true还是false?

如何从两个调用表(函数)中获取数据两次使用true还是false?

问题描述:

I have a function, responsible for knowing if a user made the purchase correctly (complete) or if the status of the purchase is (incomplete).

This function is with a single query.

function checkOrderComplete($con,$id_product,$id_user){
  $res = false; // the default result
  $stmt = $con->prepare("SELECT status FROM order WHERE id_product=? AND id_user=? AND status=? limit 1"); 
  $stmt->bind_param("iis",$id_product,$id_user,$status); 
  $status='complete'; 
  $stmt->execute();

  $stmt->store_result(); 

  if ($stmt->num_rows ===1){
    $res = true;
  } else {
    $res = false;
  }
  return $res;

}

Now I have added a new table called order_details

id_order_product  order_date  id_product  quantity  price   id_order
       1             -----          2        1       10.00     18
       2             -----          6        1       50.00     18

Order

id_order id_user  status   
  18        3    complete  

So what I want to achieve is the same functioning of the function you can realize before, it took into account the status of the purchase if it was completed or not, and the id of the product, and the id of the user who made the purchase.

Then perform the following procedure but it shows me errors in the $stmt->bind_param("isi",$id_user,$status,$id_product);

The query:

$stmt = $con->prepare("SELECT order.status, order.id_user, order_details.id_product FROM order inner join order_details ON order.id_user=? order.status=? order_details.id_product=? LIMIT 1");

How do I obtain the same values mentioned from the two tables?

我有一个函数,负责知道用户是否正确购买( complete code> )或者购买的状态是(不完整 code>)。 p>

此功能只有一个查询。 p>

   function checkOrderComplete($ con,$ id_product,$ id_user){
 $ res = false;  //默认结果
 $ stmt = $ con> prepare(“SELECT status FROM order WHERE id_product =?AND id_user =?AND status =?limit 1”);  
 $ stmt-> bind_param(“iis”,$ id_product,$ id_user,$ status);  
 $ status ='完成';  
 $ stmt-> execute(); 
 
 $ stmt-> store_result();  
 
 if($ stmt-> num_rows === 1){
 $ res = true; 
} else {
 $ res = false; 
} 
返回$ res; 
 
  } 
  code>  pre> 
 
 

现在我添加了一个名为 order_details em> strong>的新表 p>

  id_order_product order_date id_product quantity price id_order 
 1 ----- 2 1 10.00 18 
 2 ----- 6 1 50.00 18 
  code>   pre> 
 
 

订单 em> strong> p>

  id_order id_user status 
 18 3完成
  代码>  pre> 
 
 

所以我想要实现的功能与您之前可以实现的功能相同,它考虑了购买的状态(如果已完成或未完成)和id 产品的ID和购买用户的ID。 p>

然后执行以下步骤,但它显示 $ stmt-> bind_param(“isi”中的错误 “,$ id_user,$ status,$ id_product); code> p>

查询: p> \ n

  $ stmt = $ con> prepare(“SELECT order.status,order.id_user,order_details.id_product FROM order inner join order_details ON order.id_user =?  order.status =?  order_details.id_product =?  LIMIT 1“); 
  code>  pre> 
 
 

如何获得两个表中提到的相同值? p> div>

Your JOIN is not not properly formatted. The way to define a JOIN is to use the ON keyword to define what fields should be equal to perform the JOIN. Like so:

SELECT order.status,
       order.id_user,
       order_details.id_product
FROM order
INNER JOIN order_details ON order_details.id_order = order.id_order
WHERE order.id_user = ?
  AND order.status = ?
  AND order_details.id_product = ?

Then bind your parameters as required.