sql >> Base de Datos >  >> RDS >> Mysql

Búsqueda en varias columnas

<?php
    mysql_connect($dbhost, $dbuser, $dbpass) or die("could not connect.");
  mysql_select_db($dbname) or die("could not find database.");
  $result = "";
  //collect info from database
  if(isset($_POST['search'])&& $_POST['search'] != "")) {
      $searchq = $_POST['search'];
      $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);

//SQL query
      $query = mysql_query("SELECT name FROM institutes WHERE category1 LIKE '%".$searchq."%' OR category2 LIKE '%".$searchq."%' OR category3 LIKE '%".$searchq."%' OR category4 LIKE '%".$searchq."%' OR category5 LIKE '%".$searchq."%'");
      $count = mysql_num_rows($query);
      if($count == 0)
      {
          $output = "There's no search result";
      }
 else {
          while($row= mysql_fetch_assoc($query))
            {

             echo $row['name'];

            }

      }
  }
  ?>