简体   繁体   中英

how to write query search for this table in php and mysql

My dbLink Access:

dbusername:a4930120_query12
dbpassword:query12

http://sql6.000webhost.com/phpMyAdmin/index.php?db=a4930120_query12&lang=en-utf-8&convcharset=iso-8859-1&collation_connection=utf8_unicode_ci&token=d05f552925d40687254ceaee7c636758&phpMyAdmin=ucDEM,ggxf8kAny6Ki9LD0YSYqf .

I want to retrieve data based on subject and Class.column name for classes(Class_I_V Class_VI_VIII Class_IX_X Class_XI_XII).For example.my problem is how to write the search code for row no 8. they subject column contains(engg maths1,2,tpde,numerical methods,pqt,random pr...).like wise in my question is.Shall I want to give all keyword in my query(db column name is subject)?.if you see my subject column in my db.it contain all subject.I want to know how to write the proper code for this search.because user search with subject and class.As per my as per my level I have written the code.kindly make it proper. Here is my code:

<form name="f1" action="" method="post">
Enter the subject to search:
<input type="text" name="search" value="" />
<input type="submit" name="submit" value="submit"/>
</form>

search.php

<?php
if(isset($_POST['submit']))
{
$search=$_POST['search'];
$sql=mysql_query("SELECT name,subject,place,expyrs,Class_I_V FROM tutor WHERE subject LIKE '%$search%' or  subject LIKE '%$search%'  or  subject LIKE '%$search%' or subject LIKE '%$search%' or subject LIKE '%$search%' or subject LIKE '%$search%' or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%'or subject LIKE '%$search%' Or Class_I_V LIKE '%Class I -V%' ");
while($row=mysql_fetch_array($sql))
{
?>
<tr>
<td><?php echo ++$sno; ?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['subject'];?></td>
<td><?php echo $row['place'];?></td>
<td><?php echo $row['expyrs'];?></td>
<td><?php echo $row['Class_I_V'];?></td>
</tr>
<?php
}
}
?>

Myurl: http://tutorquery.comuv.com/search.php

Type here:java or Class I -V

This may be a sort solution, try this way using REGEXP

 SELECT * FROM `tutor` 
   WHERE
 subject REGEXP '^(engg maths1|tpde|numerical methods|pqt|random)$' 
 OR Class_I_V REGEXP 'Class_I_V'

See for more info that satisfy your requirements, http://dev.mysql.com/doc/refman/5.1/en/regexp.html

EDIT Sorry at first i didn't see your database columns, i think you need Full Text Search in this case. see more here http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM