在阅读了上面的原始注释和示例以及浏览了文档之后,我终于让一个循环与两个存储过程一起工作。
将第一个存储过程的结果用作第二个存储过程的参数。这样做比一大堆修改后的内部联接查询更容易。
希望这能帮助其他人…
<?php
$mysqli = new mysqli("$dbServer", "$dbUser", "$dbPass", "$dbName");
$resultPicks = $mysqli->query("CALL $proc ($searchDate, $maxRSI, $incRSI, $minMACD, $minVol, $minTrades, $minClose, $maxClose)", MYSQLI_STORE_RESULT);
while($picksRow = $resultPicks->fetch_array(MYSQLI_ASSOC)) {
$symbol = $picksRow['Symbol'];
clearStoredResults($mysqli);
$resultData = $mysqli->query("CALL prcGetLastMACDDatesBelowZero('$symbol', $searchDate)", MYSQLI_USE_RESULT);
$dataRow = $resultData->fetch_array(MYSQLI_ASSOC);
echo "<p>$symbol ... 日期数量: " . $dataRow['NumDates'];
$resultData->free();
}
$resultPicks->free();
$mysqli->close();
function clearStoredResults($mysqli_link){
while($mysqli_link->next_result()){
if($l_result = $mysqli_link->store_result()){
$l_result->free();
}
}
}
?>