我需要一些关于嵌套 sql 查询的最佳方法的建议。我写了一个新的查询来获取额外的信息,它可以作为一个独立的查询正常工作,但是当我尝试把 MoveNext(); 命令在原始之前,它会导致页面加载失败。下面我举个例子。
$new_query = "SELECT new_values,new_price
FROM new_table
WHERE new_options_id = 2
AND language = 1";
$new_result = $db->Execute($new_query);
while (!$new_result->EOF){
$newdata = $new_result->fields['new_values']
$newprice = $new_result->fields['new_price'];
$original_query = "SELECT * FROM this_table WHERE orders_id = '$ship_order_id' and class = 'ot_subtotal'";
$original_result = $db->Execute($original_query);
SOME CODE IN HERE
while (!$original_result->EOF) {
MORE CODE HERE WITH SEVERAL {
RESULTS OF ORIGINAL QUERY ARE OUTPUT
RESULTS OF NEW QUERY ARE OUTPUT
$new_result->MoveNext();
$original_result->MoveNext();
}
}
MORE CODE WITH CLOSING } FROM EARLIER CODE
问题是放入新的 MoveNext() 及其关联的 } 会终止页面加载。我确实看过将新查询的数据集合包含到原始查询中,但我的 SQL 知识有限。是否有另一种解决方法,以便我可以遍历原始循环中的结果?