doushang2571 2017-12-06 03:29
浏览 84
已采纳

如何从两个调用表(函数)中获取数据两次使用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?

  • 写回答

1条回答 默认 最新

  • douhe4336 2017-12-06 07:56
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ue5运行的通道视频都会有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数