2 つの MySQL ステートメントを 1 つに結合するのに問題があります。現時点では、それらをそれぞれ実行し、それらを配列に配置してからそれらの配列をマージする必要があります。
ここに関数があります
第1機能
/* returns all books from table book */
function getProfitableBooksNew(){
$q = "SELECT *,
ROUND((amazon_new_price/100*80) - lowest_new_price,2) AS margin
FROM ".TBL_BOOKS."
WHERE rank < 200000 AND rank IS NOT NULL
AND lowest_new_price < amazon_new_price/100*80
AND amazon_new_price < 9999
AND ROUND((amazon_new_price/100*80) - lowest_new_price) > (lowest_new_price/100*".MARGIN.")
ORDER BY rank ASC";
$result = mysql_query($q, $this->connection);
if(!$result || (mysql_numrows($result) < 1))
return null;
$arr = array();
$numRows = mysql_num_rows($result);//count
if($numRows>0){
for($i=0; $i<$numRows; $i++){
$arr[] = array(
"isbn" => mysql_result($result, $i, "isbn"),
"title" => mysql_result($result, $i, "title"),
"rank" => mysql_result($result, $i, "rank"),
"amazon_price" => mysql_result($result, $i, "amazon_new_price"),
"amazon_condition" => "New",
"lowest_price" => mysql_result($result, $i, "lowest_new_price"),
"lowest_condition" => "New",
"margin" => mysql_result($result, $i, "margin"),
"last_price_updated" => mysql_result($result, $i, "last_price_updated"),
"last_rank_updated" => mysql_result($result, $i, "last_rank_updated")
);
}
}
return $arr;
}
第2機能
/* returns all books from table book */
function getProfitableBooksUsed(){
$q = "SELECT *,
ROUND((amazon_used_price/100*80) - lowest_used_price, 2) AS margin
FROM ".TBL_BOOKS."
WHERE rank < 200000 AND rank IS NOT NULL
AND lowest_used_price < amazon_used_price/100*80
AND amazon_used_price < 9999
AND amazon_used_price < amazon_new_price
AND ROUND((amazon_used_price/100*80) - lowest_used_price) > (lowest_used_price/100*".MARGIN.")
ORDER BY rank ASC";
$result = mysql_query($q, $this->connection);
if(!$result || (mysql_numrows($result) < 1))
return null;
$arr = array();
$numRows = mysql_num_rows($result);//count
if($numRows>0){
for($i=0; $i<$numRows; $i++){
$arr[] = array(
"isbn" => mysql_result($result, $i, "isbn"),
"title" => mysql_result($result, $i, "title"),
"rank" => mysql_result($result, $i, "rank"),
"amazon_price" => mysql_result($result, $i, "amazon_used_price"),
"amazon_condition" => mysql_result($result, $i, "amazon_used_condition"),
"lowest_price" => mysql_result($result, $i, "lowest_used_price"),
"lowest_condition" => "Used",
"margin" => mysql_result($result, $i, "margin"),
"last_price_updated" => mysql_result($result, $i, "last_price_updated"),
"last_rank_updated" => mysql_result($result, $i, "last_rank_updated")
);
}
}
return $arr;
}
結合機能
/* returns profitable books */
function getProfitableBooks(){
$new = $this->getProfitableBooksNew();
$used = $this->getProfitableBooksUsed();
if($new && $used){
return array_merge($new, $used);
}else if($new){
return $new;
}else if($used){
return $used;
}else{
return null;
}
}
この問題にアプローチする方法について、誰かが少なくとも私にアイデアを与えることができますか? ありがとう