gpt4 book ai didi

php - Else 语句在选项选择中不起作用

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

我正在尝试实现下拉搜索选项。我所有的搜索结果都有效。我分配给 if 语句的所有命令都有效,但是当它分配给 else 时它就不起作用了。

这是我的代码:

if(isset($_REQUEST['submit'])){

$opt = $_POST['opt'];

if($opt==1){//if opt = 1
$sqle = "SELECT * FROM tbl_events WHERE title LIKE '%{$keywords}%'";
$resulte = mysql_query($sqle,$con) or die(mysql_error());

while($row=mysql_fetch_array($resulte)){
echo "<h4>" . $row['title'] . "</h4><br/>";
echo "<p>" . $row['description'] . "<p>";

}
}else if($opt==2){//if opt = 2
$sqls = "SELECT * FROM tbl_games WHERE games_name LIKE '%{$keywords}%'";
$results = mysql_query($sqls,$con)or die(mysql_error());

while($row=mysql_fetch_array($results)){
echo "<h4>" . $row['games_name'] . "</h4><br/>";
echo "<p>" . $row['description'] . "<p>";
}
}else{

echo "Your Searched keyword did not match";
}
}

怎么办?

最佳答案

试试这个:拿一个标志来检查记录是否存在。

$flag = false;

if($opt==1){//if opt = 1
$sqle = "SELECT * FROM tbl_events WHERE title LIKE '%{$keywords}%'";
$resulte = mysql_query($sqle,$con) or die(mysql_error());

if(mysql_num_rows($resulte) > 0) {

$flag = true;
while($row=mysql_fetch_array($resulte)){
echo "<h4>" . $row['title'] . "</h4><br/>";
echo "<p>" . $row['description'] . "<p>";

}

}

}else if($opt==2){//if opt = 2
$sqls = "SELECT * FROM tbl_games WHERE games_name LIKE '%{$keywords}%'";
$results = mysql_query($sqls,$con)or die(mysql_error());
if(mysql_num_rows($resulte) > 0) {
$flag = true;
while($row=mysql_fetch_array($results)){
echo "<h4>" . $row['games_name'] . "</h4><br/>";
echo "<p>" . $row['description'] . "<p>";
}
}
}


if(!$flag){
echo "Your Searched keyword did not match";
}

关于php - Else 语句在选项选择中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29256118/

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