Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何组合这些mysql查询_Php_Mysql - Fatal编程技术网

Php 如何组合这些mysql查询

Php 如何组合这些mysql查询,php,mysql,Php,Mysql,问题1 问题2 $query = "SELECT stock_issue.*,stock_item.item_name FROM stock_issue,stock_item WHERE stock_issue.idate>=$from AND stock_issue.idate<=$to AND stock_issue.item_id=stock_item.ID ORDER BY stock_issue.idate DESC"; 请帮帮我…你可以用

问题1

问题2

$query = "SELECT stock_issue.*,stock_item.item_name 
  FROM stock_issue,stock_item
  WHERE stock_issue.idate>=$from 
    AND stock_issue.idate<=$to 
    AND stock_issue.item_id=stock_item.ID 
ORDER BY stock_issue.idate DESC";

请帮帮我…

你可以用工会把它合并起来

$query = "SELECT stock_purchase.*,stock_item.item_name
  FROM stock_purchase,stock_item 
  WHERE stock_purchase.pdate>=$from 
    AND stock_purchase.pdate<=$to
    AND stock_purchase.itemid=stock_item.ID 
  ORDER BY stock_purchase.pdate DESC";
用UNION试试这个

(SELECT stock_issue.*,stock_item.item_name FROM stock_issue,stock_item where stock_issue.idate>=$from and stock_issue.idate<=$to and stock_issue.item_id=stock_item.ID) UNION (SELECT stock_purchase.*,stock_item.item_name FROM stock_purchase,stock_item where stock_purchase.pdate>=$from and stock_purchase.pdate<=$to and stock_purchase.itemid=stock_item.ID)
请尝试使用此代码

  $sql="SELECT stock_issue.*,stock_item.item_name FROM stock_issue,stock_item where stock_issue.idate>=$from and stock_issue.idate<=$to and stock_issue.item_id=stock_item.ID ORDER BY stock_issue.idate DESC
         UNION
        SELECT stock_purchase.*,stock_item.item_name FROM stock_purchase,stock_item where stock_purchase.pdate>=$from and stock_purchase.pdate<=$to and stock_purchase.itemid=stock_item.ID ORDER BY stock_purchase.pdate DESC";

谢谢你的回复…我收到了你的回复…我收到了
SELECT stock_issue.*,stock_item.item_name 
  FROM stock_issue,stock_item
  WHERE stock_issue.idate>='$from' 
    AND stock_issue.idate<='$to' 
    AND stock_issue.item_id=stock_item.ID 
ORDER BY stock_issue.idate DESC

UNION

SELECT stock_purchase.*,stock_item.item_name
  FROM stock_purchase,stock_item 
  WHERE stock_purchase.pdate>='$from' 
    AND stock_purchase.pdate<='$to'
    AND stock_purchase.itemid=stock_item.ID 
  ORDER BY stock_purchase.pdate DESC
$sql=$query1.'UNION'.$query2;