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

Untitled

By: a guest on Jul 17th, 2012  |  syntax: None  |  size: 0.93 KB  |  hits: 14  |  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. MySQL SELECT database entries with the same column value
  2. +----+---------+--------------+
  3. | ID | user_id | meta_key1    |
  4. +----+---------+--------------+
  5. |  1 |       1 |    d         |
  6. |  2 |       1 |    f         |
  7. |  3 |       1 |    c         |
  8. |  4 |       2 |    g         |
  9. |  5 |       3 |    1         |
  10. |  6 |       3 |    2         |
  11. |  7 |       4 |    4         |
  12. |  8 |       4 |    5         |
  13. |  9 |       4 |    5         |
  14. | 10 |       4 |    5         |
  15. +----+---------+--------------+
  16.        
  17. $query = mysql_query("SELECT * FROM table_name WHERE user_id='1'");
  18. $row = mysql_fetch_assoc($query);
  19.  
  20. while($row){
  21.     return $row["meta_key1"];
  22. }
  23.        
  24. d
  25.        
  26. d
  27. f
  28. c
  29.        
  30. while($row = mysql_fetch_assoc($query);){
  31.     echo $row["meta_key1"];
  32. }
  33.        
  34. while( $row = mysql_fetch_assoc($query)){
  35.     echo $row["meta_key1"];
  36. }
  37.        
  38. $return = array();
  39. while( $row = mysql_fetch_assoc($query)){
  40.     $return[] = $row["meta_key1"];
  41. }
  42. return $return;