Je hebt 3 vragen in je $sql, dus je moet de multi_query-functie gebruikenhttp:/ /php.net/manual/en/mysqli.multi-query.php
En u kunt uw eerste zoekopdracht wijzigen in:
SET @uid = 0;
SELECT @uid := ID FROM channels WHERE Used = 0 ORDER BY RAND() LIMIT 1);
Bijwerken Je kunt dit fragment van je code proberen, aangepast met alle verbeteringen die zijn opgemerkt.
$sql = 'SET @uid = 0;';
$sql .= 'SELECT @uid:= ID FROM channels WHERE Used = 0 ORDER BY RAND() LIMIT 1);';
$sql .= 'UPDATE channels SET Used = 1 WHERE ID = @uid;';
$sql .= 'SELECT * FROM channels WHERE ID IN = @uid;';
if (mysqli_multi_query($conn, $sql)) {
do {
$result = mysqli_store_result($conn);
} while(mysqli_next_result($conn));
if (mysqli_num_rows($result) > 0) {
$text = '';
while($row = mysqli_fetch_assoc($result)) {
$Channel_Location = $row['Channel_Location'];
$text = $text . $Channel_Location;
}
}
} else {
die( mysqli_error($conn) );
}