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

Untitled

By: a guest on Jun 26th, 2012  |  syntax: None  |  size: 1.07 KB  |  hits: 11  |  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. Storing database records into array
  2. <?php
  3.  
  4. // run query
  5. $query = mysql_query("SELECT * FROM table");
  6.  
  7. // set array
  8. $array = array();
  9.  
  10. // look through query
  11. while($row = mysql_fetch_assoc($query)){
  12.  
  13.   // add each row returned into an array
  14.   $array[] = $row;
  15.  
  16.   // OR just echo the data:
  17.   echo $row['username']; // etc
  18.  
  19. }
  20.  
  21. // debug:
  22. print_r($array); // show all array data
  23. echo $array[0]['username']; // print the first rows username
  24.        
  25. if (isset($_GET['search'])) {
  26.   $search = mysql_real_escape_string($_GET['search']);
  27.   $sql = "SELECT * FROM users WHERE username = '$search'";
  28.   $res = mysql_query($sql) or trigger_error(mysql_error().$sql);
  29.   $row = mysql_fetch_assoc($res);
  30.   if ($row){
  31.     print_r($row); //do whatever you want with found info
  32.   }
  33. }
  34.        
  35. $mysearch="Your Search Name";
  36. $query = mysql_query("SELECT * FROM table");
  37. $c=0;
  38. // set array
  39. $array = array();
  40.  
  41. // look through query
  42. while($row = mysql_fetch_assoc($query)){
  43.  
  44.   // add each row returned into an array
  45.   $array[] = $row;
  46.   $c++;
  47. }
  48.  
  49. for($i=0;$i=$c;$i++)
  50. {
  51. if($array[i]['username']==$mysearch)
  52. {
  53. // name found
  54. }
  55. }