我正在尝试找出如何使用表单中的一个文本字段来搜索数据库表中的任何列。
现在它只是在我的名为 stock 的数据库表的 sn 列中搜索。我需要它来搜索列名 sn 或用户或状态。
因此,如果您输入序列号并发布表格,它将搜索我的数据库并毫无问题地返回结果。但我希望能够输入用户的姓名或状态并以这种方式搜索我的数据库。所以我在想一些如何用单选按钮动态更改 Input name="" 以将值更改为 Input name="sn" 或 Input name="user" 或 Input name="status" 但我不确定怎么做。我一直在阅读其他人用 Javascript 或 JQuery 说的话。我真的很感激任何帮助。谢谢!
我的记录集只能查询 sn 列。我确定我也需要更改此设置,但我不确定如何更改。
表格
<form id="form1" name="form1" method="get" action="search.php">
<label>
<input type="radio" name="RadioGroup1" value="sn" id="RadioGroup1_0" />
sn</label><br />
<label>
<input type="radio" name="RadioGroup1" value="user" id="RadioGroup1_1" />
User</label>
<br />
<label>
<input type="radio" name="RadioGroup1" value="status" id="RadioGroup1_2" />
Staus</label>
<br />
</p>
<label for="sn"> Search :</label>
<input name="sn" type="text" id="sn" size="25" />
<input name="submit" type="submit" value="submit" />
</form>
SQL
SELECT *
FROM stock
WHERE sn = colname
ORDER BY `datetime` DES
php
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string ($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_Recordset567 = 10;
$pageNum_Recordset567 = 0;
if (isset($_GET['pageNum_Recordset567'])) {
$pageNum_Recordset567 = $_GET['pageNum_Recordset567'];
}
$startRow_Recordset567 = $pageNum_Recordset567 * $maxRows_Recordset567;
$colname_Recordset567 = "-1";
if (isset($_GET['sn'])) {
$colname_Recordset567 = $_GET['sn'];
}
mysql_select_db($database_stock, $stock);
$query_Recordset567 = sprintf("SELECT * FROM stock WHERE sn = %s ORDER BY `datetime` DESC", GetSQLValueString($colname_Recordset567, "text"));
$query_limit_Recordset567 = sprintf("%s LIMIT %d, %d", $query_Recordset567, $startRow_Recordset567, $maxRows_Recordset567);
$Recordset567 = mysql_query($query_limit_Recordset567, $stock) or die(mysql_error());
$row_Recordset567 = mysql_fetch_assoc($Recordset567);
if (isset($_GET['totalRows_Recordset567'])) {
$totalRows_Recordset567 = $_GET['totalRows_Recordset567'];
} else {
$all_Recordset567 = mysql_query($query_Recordset567);
$totalRows_Recordset567 = mysql_num_rows($all_Recordset567);
}
$totalPages_Recordset567 = ceil($totalRows_Recordset567/$maxRows_Recordset567)-1;
?>