最初のクエリの結果を使用して 2 番目のクエリを実行し、取得したばかりのすべての行にフラグを設定しようとしています。最初に結果を使用して JSON を出力すると正常に動作しますが、2 回目に結果を呼び出そうとするとfetch_assoc()
、配列が NULL に戻ります。
$result = API::$connection->query($query);
if (!mysqli_error(API::$connection))
{
API::setHeader(200);
// return json encoded results
/// This works just fine, outputs JSON
echo JSONizer::jsonEncodeSqlResultWithKeys( $result, array (
'pId',
'sender',
'receiver',
'content',
'notified',
'opened',
'time' ) );
// initial update query
$query = 'UPDATE messages
SET received=1
WHERE ';
// start by cycling through each pId received and tack each onto query
$counter = 0;
// this never runs because the associated array returns NULL now
while ($row = mysqli_fetch_assoc($result));
{
$pId = $row['pId'];
// concat query
$query .= 'pId='.$pId;
// if there's still more to go, tack on OR
if ($counter++ != count($result))
{
$query .= ' OR';
}
else
{
$query .= ';';
}
}
の呼び出しでオブジェクトと手続き型のスタイルを試しましたがfetch_assoc
、違いはありませんでした。結果を別の変数にコピーして使用しようとしましたが、それも NULL でした。これが 1 回だけ機能するのに、2 回目は機能しないのはなぜですか。