gpt4 book ai didi

php - 显示 'All Records' 选项

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

我整理了下面的表单,允许用户从下拉菜单中选择的日期检索数据库记录。

<html>
<head>
<script type="text/javascript">

function ajaxFunction(name)
{
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}
else
{// code for IE6, IE5
xmlhttp=new XMLHttpRequest();

}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("my_div").innerHTML=xmlhttp.responseText;
}
}

xmlhttp.open("GET","getrecords.php?dateoftrip="+name,true);
xmlhttp.send();
}

function getquerystring() {
var form = document.forms['frm1'];
var word = form.word.value;
qstr = 'w=' + escape(word); // NOTE: no '?' before querystring
return qstr;
}


</script>


<style type="text/css">
<!--
.style1 {
font-family: Calibri;
font-size: 14px;
}
-->
</style>
</head>
<body>

<form action="getrecords.php" method="get" name="frm1">

<table width="148" border="0">

<tr>
<td width="152"><p class="style1">Select a date from below</p>
<div align="center">
<?php
include("db.php");

$query="select * from finds group by dateoftrip";
echo '<select onchange="ajaxFunction(this.value)">';
$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){

echo "<option name='name' value=".$rows['dateoftrip'].">".$rows['dateoftrip']."</option>";

}
echo "</select>";
?>
</div></td>
</tr>
</table>
</form>
<div id="my_div"></div>
</body>
</html>

这是检索记录的 php 脚本。

<?php
include("db.php");
$dateoftrip= $_GET['dateoftrip'];
$findname= $_GET['findname'];
$finddescription= $_GET['finddescription'];

$query="select * from finds where dateoftrip='$dateoftrip'";
echo "<table>";
$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){

echo "<tr>";
echo "<td>Find Name : </td>";
echo "<td>".$rows['findname']."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Find Description : </td>";
echo "<td>".$rows['finddescription']."</td>";
echo "</tr>";
}
echo "</table>";
?>

如果可能的话,我想通过在下拉菜单中添加“所有记录”选项来扩展该功能,该选项显然会返回当前用户的所有记录。

我已经搜索了几天了,但还没有找到具有此附加功能的示例。

我只是想知道是否有人可以提供一些指导,告诉我如何解决这个问题。

修改后的表单代码

<html>
<head>
<script type="text/javascript">

function ajaxFunction(name)
{
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}
else
{// code for IE6, IE5
xmlhttp=new XMLHttpRequest();

}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("my_div").innerHTML=xmlhttp.responseText;
}
}

xmlhttp.open("GET","getrecords.php?dateoftrip="+name,true);
xmlhttp.send();
}

function getquerystring() {
var form = document.forms['frm1'];
var word = form.word.value;
qstr = 'w=' + escape(word); // NOTE: no '?' before querystring
return qstr;
}


</script>


<style type="text/css">
<!--
.style1 {
font-family: Calibri;
font-size: 14px;
}
-->
</style>
</head>
<body>

<form action="getrecords.php" method="get" name="frm1">

<table width="148" border="0">

<tr>
<td width="152"><p class="style1">Select a date from below</p>
<div align="center">
<?php
include("db.php");

$query="select * from finds group by dateoftrip";
echo '<select onchange="ajaxFunction(this.value)"><OPTION name="name" value="ALLRECORDS">';
$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){

echo "<option name='name' value=".$rows['dateoftrip'].">".$rows['dateoftrip']."</option>";

}
echo "</select>";
?>
</div></td>
</tr>
</table>
</form>
<div id="my_div"></div>
</body>
</html>

最佳答案

为“ALL”事物创建一个选项

echo '<select onchange="ajaxFunction(this.value)"><OPTION name="name" value="ALLRECORDS">All Records</option>';
<小时/>

处理“ALL”事物的查询

if ($dateoftrip=="ALLRECORDS") {
$query="select * from finds";
} else {
$query="select * from finds where dateoftrip='$dateoftrip'";
}

顺便说一句,您应该了解SQL注入(inject),不要使用“*”选择器,而是输入您搜索的属性的显式名称

关于php - 显示 'All Records' 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9740119/

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