我想显示用户在搜索框中输入的特定记录的详细信息,并在用户单击按钮后将其存储到HTML表中。
但是,我无法弄清楚相同条件是什么。请帮忙。
我的PHP代码是:
<?php
$calldetails = $_POST["call"];
$link = mysqli_connect("server_name","username","password","database_name") or die("Error: Unable to connect:". mysqli_connect_error());
if($calldetails)
{
$sql = "select * from table_name";
if($result = mysqli_query($link,$sql))
{
if(mysqli_num_rows($result)>0)
{
echo "<table class='table table-stripped table-hover table-condensed table-border'>
<tr>
<th>Mobile Number</th>
<th>Called Number</th>
<th>Date and Time of Call</th>
<th>Duration</th>
<th>Date of Last Recharge</th>
<th>Amount of Last Recharge</th>
</tr>";
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
echo "<tr>";
echo "<td>" .$row["Mobile"] . "</td>";
echo "<td>" .$row["Called_Num"] . "</td>";
echo "<td>" .$row["Date_Time"] . "</td>";
echo "<td>" .$row["Duration"] . "</td>";
echo "<td>" .$row["Last_recharge"] . "</td>";
echo "<td>" .$row["Amount"] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_free_result($result);
}
else
echo "mySQL returned an empty result set.";
}
}
?>
另外,如果用户未在搜索框中输入任何内容,我想显示一个警报。我的代码即使在空搜索中也显示记录。请告诉我我缺少什么条件。
附言我是PHP新手,仍处于学习阶段。
最佳答案
如果执行$sql = "select * from table_name";
,它将返回整个表。即使用户未在搜索框中输入任何内容!
在您的代码上,您正在获取一些POST数据$calldetails = $_POST["call"];
。如果要显示与$ calldetails相关的数据。使用WHERE
条件
示例:SELECT * FROM table_name WHERE column_name = $calldetails
关于php - 显示特定记录的详细信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46048881/