Advertisement
jchaven

Get first row value from array

Jan 29th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 KB | None | 0 0
  1. http://stackoverflow.com/questions/5366620/storing-database-records-into-array
  2.  
  3. <?php
  4.  
  5. // run query
  6. $query = mysql_query("SELECT * FROM table");
  7.  
  8. // set array
  9. $array = array();
  10.  
  11. // look through query
  12. while($row = mysql_fetch_assoc($query)){
  13.  
  14.   // add each row returned into an array
  15.   $array[] = $row;
  16.  
  17.   // OR just echo the data:
  18.   echo $row['username']; // etc
  19.  
  20. }
  21.  
  22. // debug:
  23. print_r($array); // show all array data
  24. echo $array[0]['username']; // print the first rows username
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement