gpt4 book ai didi

php - 使用php使用更多关键字搜索mysql数据库

转载 作者:行者123 更新时间:2023-11-29 03:37:14 25 4
gpt4 key购买 nike

基于种姓、宗教、地点、性别、年龄,我需要从我的数据库中过滤数据,我该怎么做。

在 mysql 数据库中,我将宗教、性别、位置、年龄作为同一个表中的单独列。

我用过的代码

$result=mysql_query("SELECT * FROM enquiry where location like '%$text%'and gender like'%$text1%' ")
or die("error");
$found=mysql_num_rows($result);

if($found>0){
while($row=mysql_fetch_array($result)){
//display of data
}

使用它,我可以使用一个关键字从一列中搜索数据...因为我是新手,请给我正确的方法来使用 php 解决这个问题。

最佳答案

使用或运算符

$result=mysql_query("SELECT * FROM enquiry where location like '%$text%' OR caste like '%$text%' OR religion like '%$text%' OR gender like '%$text%' OR age like '%$text%'")
or die("error");
$found=mysql_num_rows($result);

if($found>0){
while($row=mysql_fetch_array($result)){
//display of data
}

关于php - 使用php使用更多关键字搜索mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19656830/

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