我正在我的php代码中执行multi_query并希望在表中回显结果。查询按预期工作并产生所需的输出,但是当我回显数据时,while循环似乎在一次迭代后停止。
以下是我要使用的代码:
if (mysqli_multi_query($db_conx, $sql)) {
do {
/* store first result set */
if ($result = mysqli_store_result($db_conx)) {
while ($row = mysqli_fetch_row($result)) {
$cur = $row[1];
$date = $row[7];
$et = $row[9];
$result = $row[13];
$payout = $row[15];
echo '<tr>
<th class="text-center" scope="row">'. $cur .'</th>
<td>'. $date .'</td>
<td>'. $et .'</td>
<td>'. $result .'</td>
<td>'. $payout .'</td>
</tr>';
}
mysqli_free_result($result);
}
} while (mysqli_next_result($db_conx));
}
运行此代码将返回表格的第一行,但之后不再签名。当我测试一些东西时,我注意到如果我只引用其中一行,我能够检索/回显所有内容:
if (mysqli_multi_query($db_conx, $sql)) {
do {
/* store first result set */
if ($result = mysqli_store_result($db_conx)) {
while ($row = mysqli_fetch_row($result)) {
$cur = $row[1];
echo $cur;
echo '<br>';
}
mysqli_free_result($result);
}
} while (mysqli_next_result($db_conx));
}
任何人都可以帮助我吗?我非常感谢你的帮助!
更新:我正在使用的查询(由于测试原因而硬插入的条件值)
SET @row_number_t1:=0;
SET @row_number_t2:=0;
CREATE TEMPORARY TABLE IF NOT EXISTS t1 AS (
SELECT cur,date,time_start FROM `cur1` WHERE sig = 5
);
INSERT INTO t1
SELECT cur,date,time_start FROM `cur1` WHERE (sig = 1 OR sig = 2) AND error_code = 0 AND date >= '2016-02-01' AND date <= '2016-02-010'
UNION SELECT cur,date,time_start FROM `cur2` WHERE (sig = 1 OR sig = 2) AND error_code = 0 AND date >= '2016-02-01' AND date <= '2016-02-010'
ORDER BY time_start ASC, date;
SELECT t1_modif.*, t2_modif.* FROM
(SELECT @row_number_t1:=@row_number_t1+1 AS row_number1,
cur,time_start FROM t1)
t1_modif
JOIN (SELECT @row_number_t2:=@row_number_t2+1 AS row_number2,
trades.* FROM trades WHERE date >= '2016-02-01' AND date <= '2016-02-010'
ORDER BY startTime ASC, date)
t2_modif ON t2_modif.row_number2 = t1_modif.row_number1;