gpt4 book ai didi

Php/MySQL if 语句根据所选值返回信息

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

[page1.php]

<form action="result.php" method="POST" style='color:white;font-family: __custom;'>
<input type="text" placeholder="Search.." name="search" /><br><br>
<center>
<select name="example">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
<br><br>
</center>
&nbsp;<input type="submit" value="GO!" id="sub"/>
</form><br><br><br>

[结果.php]

<?php
$searchq = $_POST['search'] // search textbox;
//Connect to mySQL and retrieve all contacts
$conErr = "Error connecting to server or database";
$con = mysqli_connect("host", "user", "password", "database");
// Check connection
if (mysqli_connect_errno()) {
echo $connErr;
}
if ($_POST['example'] == 'C') {
echo "You chose inCludes";
$result = mysqli_query($con, "SELECT * FROM people WHERE name LIKE '%$searchq%' ORDER BY name ASC");
while ($row = mysqli_fetch_array($result)) {
echo "<hr>";
echo "All information regarding Select Statement";
echo "<br>";
}
} else if ($_POST['example'] == 'A') {
echo "You chose EndsWith";
$result = mysqli_query($con, "SELECT * FROM people WHERE name LIKE '$searchq%' ORDER BY name ASC");
while ($row = mysqli_fetch_array($result)) {
echo "<hr>";
echo "All information based on Select Statement";
echo "<br>";
}
} else {
echo "Blah";
}
mysqli_close($con);
?>
</div>

我想做的是在 page1.php 上用户搜索关键字并从下拉列表中选择 A、B 或 C。根据A、B、C,用户转到result.php,然后根据查询给出信息。

上面的代码似乎不起作用[我根本没有得到任何结果][空白]。请帮忙。

最佳答案

如果要搜索以字符串结尾的内容,则必须在开头放置 % 通配符:

} else if ($_POST['example'] == 'A') {
echo "You chose EndsWith";
$result = mysqli_query($con, "SELECT * FROM people WHERE name LIKE '%$searchq' ORDER BY name ASC");
while ($row = mysqli_fetch_array($result)) {
echo "<hr>";
echo "All information based on Select Statement";
echo "<br>";
}
}

关于Php/MySQL if 语句根据所选值返回信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25775515/

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