php - Select All MySQL Rows -


i have following code choose rows in mysql show last row only

    $query = mysql_query("select * `users`") or die(mysql_error());      while ( $row = mysql_fetch_assoc($query) )           {           $token = $row['instagram_access_token'];           }           echo "$token"; 

your code echo last row because, within while loop every time overwrites $token value new value. try connect using pdo & assign variable array this.

 $token=[];  $user='your_user_name';  $pass='your_password';  $conn= new pdo('mysql:host=your_host_name;dbname=your_db_name', $user, $pass);  $query = $conn->prepare('select * `users`');  $query->execute(); // alternatively use pdostatement::fetchall() , rid of loop while ($row = $query->fetch(pdo::fetch_assoc)) {     $token[] = $row['instagram_access_token']; // see line [] }   echo '<pre>';  print_r($token);  echo '</pre>'; 

note: don't use mysql_* see more here why shouldn't use mysql_* functions in php?


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -