Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Mencari di beberapa kolom

<?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'];

            }

      }
  }
  ?>



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. C# Menggunakan parameter sql yang sekarang tidak berfungsi

  2. PDO - Ambil Assoc dalam loop 'sementara'

  3. Prosedur tersimpan MySQL mengembalikan nilai

  4. bagaimana cara menggunakan variabel dalam membuat pernyataan basis data?

  5. Menetapkan output kueri BQ ke variabel