Mysql
 sql >> Database >  >> RDS >> Mysql

PHP non visualizza il risultato della query MySQL

Hai 3 query nel tuo $sql quindi dovresti usare la funzione multi_queryhttp:/ /php.net/manual/en/mysqli.multi-query.php

E puoi modificare la tua prima query in:

SET @uid = 0;
SELECT @uid := ID FROM channels WHERE Used = 0 ORDER BY RAND() LIMIT 1);

Aggiorna Puoi provare questo frammento del tuo codice modificato con tutti i miglioramenti commentati.

$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) );
}