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.

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

报告相同问题?

悬赏问题

  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果