Storing database records into array

前端 未结 4 1084
无人及你
无人及你 2020-12-14 04:07

I would want to create an array that will hold records retrieved from a database using a query of SELECT statement.

The records to be retrieved have multiple fields

4条回答
  •  死守一世寂寞
    2020-12-14 04:25

    You shouldn't search through that array, but use database capabilities for this
    Suppose you're passing username through GET form:

    if (isset($_GET['search'])) {
      $search = mysql_real_escape_string($_GET['search']);
      $sql = "SELECT * FROM users WHERE username = '$search'";
      $res = mysql_query($sql) or trigger_error(mysql_error().$sql);
      $row = mysql_fetch_assoc($res);
      if ($row){
        print_r($row); //do whatever you want with found info
      }
    }
    

提交回复
热议问题