简体   繁体   English

如何在php和mysql中编写查询此表的查询

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

My dbLink Access: 我的dbLink访问:

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 . http://sql6.000webhost.com/phpMyAdmin/index.php

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. 我想根据主题和类(Class_I_V Class_VI_VIII Class_IX_X Class_XI_XII)的Class.column名称检索数据。例如。我的问题是如何编写第8行的搜索代码,它们的主题列包含(ength maths1,2,tpde ,数值方法,pqt,随机pr ...)。在我的问题中是明智的。我是否要在查询中提供所有关键字(db列名称为subject)?.如果您在db.it中看到我的subject列包含所有主题。我想知道如何为此搜索编写正确的代码。因为用户使用主题和类进行搜索。按照我的水平,我已经编写了代码。请使其正确。 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 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 Myurl: http ://tutorquery.comuv.com/search.php

Type here:java or Class I -V 在这里输入:java或Class I -V

This may be a sort solution, try this way using REGEXP 这可能是一种排序解决方案,请使用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 有关更多信息,请参见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 在此处查看更多信息http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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