gpt4 book ai didi

php - 如何在 php 和 mysql 中编写对该表的查询搜索

转载 作者:行者123 更新时间:2023-11-29 23:07:07 24 4
gpt4 key购买 nike

我的 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 .

我想根据主题和类检索数据。类的列名称(Class_I_V Class_VI_VIII Class_IX_X Class_XI_XII)。例如。我的问题是如何编写第8行的搜索代码。它们的主题列包含(engg maths1, 2,tpde,数值方法,pqt,随机pr...)。我的问题是。我想在我的查询中给出所有关键字吗(数据库列名称是主题)?。如果您在我的主题中看到我的主题列db.it 包含所有主题。我想知道如何为此搜索编写正确的代码。因为用户使用主题和类别进行搜索。根据我的水平,我已经编写了代码。请使其正确。这是我的代码:

<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>

搜索.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
}
}
?>

我的网址:http://tutorquery.comuv.com/search.php

在此输入:java 或 Class I -V

最佳答案

这可能是一个排序解决方案,请使用REGEXP尝试这种方式

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

查看满足您要求的更多信息,http://dev.mysql.com/doc/refman/5.1/en/regexp.html

编辑抱歉,一开始我没有看到您的数据库列,我认为在这种情况下您需要全文搜索。在这里查看更多 http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

关于php - 如何在 php 和 mysql 中编写对该表的查询搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28252966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com