php - 过滤Mysql中的数据
问题描述
我试图“过滤”这些数据,以便 [bøde]...
唯一得到回显。而不是所有其他数据。
我怎样才能做到这一点?我完全不知道。
我试图[bøde]
在此表中回显:
“测试”在哪里。
这vrp_user_data
就是问题所在,我不知道如何过滤它,所以它不会回显所有的 dvalue 数据
<?php
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `vrp_user_identities`, `vrp_user_data` WHERE CONCAT(`user_id`, `firstname`, `name`, `age`, `phone`, `registration` ) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `vrp_user_identities`, `vrp_user_data` ";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("xxx", "xxx", "xxx", "xxx");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>FOLKEREGISTER</title>
</head>
<body><center>
<center><h1>søg i det centrale personregister "CPR"</h1></center>
<form action="https://mesogames.dk/DDC/FOLKEREGISTER.php" method="post">
<input type="text" name="valueToSearch" placeholder="SØG I CPR"><br><br>
<input type="submit" name="search" value="søg/genlæs"><br><br>
<table>
<tr>
<th>Fornavn</th>
<th>Efternavn</th>
<th>Alder</th>
<th>CPR</th>
<th>Telefon nummer</th>
<th>Test</th>
</tr>
<!-- populate table from mysql database -->
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['firstname'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['age'];?></td>
<td><?php echo $row['registration'];?></td>
<td><?php echo $row['phone'];?></td>
<td><?php echo $row['dvalue'];?></td>
</tr>
<?php endwhile;?>
</table>
</form>
</body></center>
</html>
我的英语不太好,所以如果您想了解更多信息,请随时帮助我:)
解决方案
我不太明白你的意思,但如果我错了,我会纠正我你是否正在尝试构建搜索查询?
如果是这样,您无法像在那里那样从 2 个表中搜索,则必须使用内部联接进行 2 个查询:
$query = "SELECT column-names FROM table-name1 JOIN table-name2 ";
现在添加您其余的参数,希望它对您有所帮助,否则请让我知道我不是您要找的这个。
推荐阅读
- java - 使用 ANTLR4(Java、Python)的语言语法元模型
- ios - APNS aps 字典中的内容可用和警报互斥键
- powershell - 如何使用 PowerShell 检查用户是否通过日期是星期三?
- ios - 生成具有 CoreData 等属性的 CKRecord 类
- javascript - Angular rxjs:延迟订阅直到其他 Observable 发出
- python - 用于反向排序日期的 Ironpython 脚本 + 必须从 Spotfire 7.8 中的列(过滤器类型:列表框)中选择最新日期?
- java - 如何通过 DataOutputStream 发送算术运算的有效结果
- c++ - 如何在 wxSmith 中定义新的框架类型?
- python - 一次用多个标记标记 test_
- ios - 如何使用 EXPO iOS StoreReview API?