php - Array to string conversion error when indexing array -


this question has answer here:

it says i'm getting these errors:

notice: array string conversion in c:\xampp\htdocs\team_aveera_website\inc\user_functions.php on line 19 array notice: array string conversion in c:\xampp\htdocs\team_aveera_website\inc\user_functions.php on line 22

when try index array. i'm doing getting rows database , adding value row array. random object array:

<?php     function getrandomadminstream($db) {         try {             $twitchnames[] = array();              $sql = $db->prepare('select * users');             $sql->setfetchmode(pdo::fetch_assoc);             $sql->execute();              $i = 0;             while($row = $sql->fetch() !== false) {                 if($row['rank'] == 1) {                     $twitchnames[$i] = $row['twitchusername'];                     $i++;                 }             }              $random = $twitchnames[rand(0, count($twitchnames) - 1)];             echo $random;              echo '<iframe id="home-stream" type="text/html" height="420"                 src="http://www.twitch.tv/'.$random.'/embed"                 frameborder="0"></iframe>                 <div class="info-holder">                 </div>';         } catch (pdoexception $e) {             echo $e->getmessage();         }     } ?> 

even though set fetch mode:

$sql->setfetchmode(pdo::fetch_assoc); 

it still wouldnt use associative array in while loop, had change statement so:

while($row = $sql->fetch(pdo::fetch_assoc)) {} 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -