title: PHP search in MySQL
body: <p>I'm trying to make a search function on this website that loops through my <code>$result_array</code>. I've tried a bunch of different approaches on my own but to no avail. Thought it was about time I asked here. This is my code:</p>
  
  <pre><code>&lt;?php
  
              include 'database_info.php';
  
              $search_string = $_POST['search1'];
              $query = "SELECT * FROM customers_info WHERE first_name='$search_string'";
  
              //Try to query the database
              if($result = $data_connect-&gt;query($query)){
                  echo '&lt;br /&gt;&lt;br /&gt;Successfully sent query!&lt;br /&gt;&lt;br /&gt;';   
              }
              else {
                  echo 'Error getting customers from the database: '.mysqli_error($data_connect).'&lt;br /&gt;'; 
              }
  
              //Create Table
              echo "&lt;table id='Grid'&gt;&lt;tr&gt;";
              echo "&lt;th&gt;customer_id&lt;/th&gt;";
              echo "&lt;th&gt;First Name&lt;/th&gt;";
              echo "&lt;th&gt;Last Name&lt;/th&gt;";
              echo "&lt;th&gt;Email&lt;/th&gt;";
              echo "&lt;th&gt;Country&lt;/th&gt;";
              echo "&lt;tr&gt;\n";
  
              $class = "odd"; //Keep track of whether a row is equal or odd
  
              //Loop through all the rows returned by the query, creating a table row for each
              while($result_array = mysqli_fetch_assoc($result)){
  
  
                  echo "&lt;tr class=\"$class\"&gt;";
                  echo "&lt;td&gt;".$result_array['customer_id']."&lt;/td&gt;";
                  echo "&lt;td&gt;&lt;a href='view_customer.php?email=".$result_array['email']."'&gt;" .$result_array['first_name']. "&lt;/a&gt;&lt;/td&gt;";
                  echo "&lt;td&gt;" .$result_array['last_name']. "&lt;/td&gt;";
                  echo "&lt;td&gt;" .$result_array['email']. "&lt;/td&gt;";
                  echo "&lt;td&gt;" .$result_array['country']. "&lt;/td&gt;";
                  echo "&lt;/td&gt;&lt;/tr&gt;\n";
  
                  //If the last row was even make the next one odd
                  if($class =="odd"){
                      $class ="even";
                  }
                  else{
                      $class = "odd";
                  }
              }
  
  
  
              echo "&lt;/table&gt;";
  
              $data_connect-&gt;close();
  
          ?&gt;
  </code></pre>
  
  <p>Can anybody tell me a way I could accomplish this? A function or approach I could use? </p>
  
  <p>P.S.</p>
  
  <p>My current approach is to alter the query, this does work but then I can only search for the customer first_name for example. I want to be able to search for email address or last_name or country. These are all columns in my database.</p>