Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 23rd, 2012  |  syntax: None  |  size: 0.54 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP MySql - How to extract specific records of a query result?
  2. $myQuery = mysql_query(...);
  3.        
  4. while($row = mysql_fetch_assoc($myQuery)) {  
  5.     ???
  6. }
  7.        
  8. $first_record = array();
  9. while($row = mysql_fetch_assoc($myQuery)) {  
  10.     if(count($first_record) == 0) {
  11.         $first_record = $row;
  12.     } else {
  13.         // not the first record
  14.     }
  15. }
  16.        
  17. $array = array();
  18. while ($row = mysql_fetch_assoc($query)) {
  19.     $array[] = $row;
  20. }
  21.        
  22. $last = count($array);
  23. echo $array[0]['username'];
  24. echo $array[2]['username'];
  25. echo $array[$last - 1]['username'];