显示特定记录的详细信息

时间:2017-09-05 07:06:39

标签: php mysql

我希望在用户点击按钮后显示用户输入搜索框并将其存储到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.";
                        }
                    }
            ?>

另外,如果用户没有在搜索框中输入任何内容,我想显示提醒。我的代码甚至在空搜索时显示记录。请告诉我错过了什么条件。

P.S。我是PHP的新手,还处于学习阶段。

3 个答案:

答案 0 :(得分:1)

无论用户进入搜索框,您的查询WHERE都将始终返回整个表格。

考虑使用 while True: ret, img = cap.read() input_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) detected = detector(input_img, 1) current_viewers = len(detected) if current_viewers > last_total_current_viewers: user_id += current_viewers - last_total_current_viewers last_total_current_viewers = current_viewers for i, d in enumerate(detected): x1, y1, x2, y2, w, h = d.left(), d.top(), d.right() + 1, d.bottom() + 1, d.width(), d.height() cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 0), 2) cv2.putText(img, str(user_id), (x1, y1), font, 0.5, (255, 255, 255), 1, cv2.LINE_AA) cv2.imshow("result", img) key = cv2.waitKey(30) if key == 27: break 子句来过滤结果。

答案 1 :(得分:1)

如果执行$sql = "select * from table_name";它将返回整个表。即使用户在搜索框中没有输入任何内容!

在您的代码中,您获得了一些POST数据$calldetails = $_POST["call"];。如果要显示与 $ calldetails 相关的数据。使用WHERE条件

示例: SELECT * FROM table_name WHERE column_name = $calldetails

答案 2 :(得分:1)

你有火灾查询&#34;从表格中选择*&#34;  而不是你必须传递参数  搜索框从表名中选择*,其中&#34; &#34; ; 假设您从搜索框中取名,所以就这样做 $名称= $ _ POST [&#39; NAME_OF_SEARCH_BOX&#39;]; 然后激活查询select * from tablename where name = $ name;像这样的东西

相关问题