如何创建搜索/过滤表并添加分页? [英] How to create search/filter table and add pagination?

查看:61
本文介绍了如何创建搜索/过滤表并添加分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我需要你的帮助。我的代码出错,我的编译器说mysq_query()expert参数1是字符串,资源给定test.php第21行和mysql_fetch_array()期望参数1是资源,在第72行的test.php中给出null 我无法弄清楚如何解决这个错误,我不知道如何在我的代码上添加分页,我想知道如果过滤器没有结果我怎么能显示任何消息。 。请查看并查看下面的代码。预先感谢您的帮助。 :)



这是我的代码:

Hi everyone!, I need your help. I got an error in code, my compiler said "mysq_query() experts parameter 1 to be string, resource given test.php line 21" and "mysql_fetch_array() expects parameter 1 to be resource, null given in test.php on line 72" and I can't figure out how to solve this errors and I don't know how I will add pagination on my codes and I would like to know how I can show any message when there is no result from the filters. . Please see and check my codes below. Thank you in advance for your help. :)

Here is my codes:

<?php

if(isset($_POST['search']))
{
    $valueToSearch = $_POST['valueToSearch'];
    // search in all table columns
    // using concat mysql function
    $query = "SELECT * FROM `dbcharity2016` WHERE CONCAT(`genNo`, `reliefNo`, `disas_date`, `area`, `city`, `type`, `surv_date`, `surv_date`, `surv_volunteers`, `vol_incharge`, `relief_date`, `volunteers`, `venue`, `T_Beneficiary`, `unit`, `individual`, `house`, `sacksNo`, `DRG`, `cost_set`, `cost_relief`, `DAI`, `CAG`, `TCA`) LIKE '%".$valueToSearch."%'";
    $search_result = filterTable($query);
    
}
 else {
    $query = "SELECT * FROM `dbcharity2016`";
    $search_result = filterTable($query);
}

// function to connect and execute the query
function filterTable($query)
{
    $con = mysql_connect("localhost","test_webdev","e7#_AZ*9we_^","test_WebBase");
    $filter_Result = mysql_query($con, $query);
    return $filter_Result;
}

?>
<!DOCTYPE html>
<html>
    <head>
        <title>test</title>
        <style>
            table,tr,th,td
            {
                border: 1px solid black;
            }
        </style>
    </head>
    <body>
        
        <form action="test.php" method="post">
            <input type="text" name="valueToSearch" placeholder="Value To Search"><br><br>
            <input type="submit" name="search" value="Filter"><br><br>
            
            <table>
                <tr>
                    <th>General No.</th>
                    <th>Relief No.</th>
                    <th>Disaster Date</th>
                    <th>Area</th>
                    <th>City</th>
                    <th>Relief type</th>
                    <th>Survey Date</th>
                    <th>Survey Volunteers</th>
                    <th>Volunteer-in-Charge</th>
                    <th>Relief Date</th>
                    <th>Volunteers</th>
                    <th>Venue</th>
                    <th>Beneficiary</th>
                    <th>Unit</th>
                    <th>Individual</th>
                    <th>House</th>
                    <th>No. of Sacks</th>
                    <th>Details of Relief Goods</th>
                    <th>Cost per set</th>
                    <th>Cost of Relief Goods
                    <th>Death and Injuries</th>
                    <th>Cash Assistance</th>
                    <th>Total Cash Assistance</th>

                </tr>

      <!-- populate table from mysql database -->
                <?php while($row = mysql_fetch_array($search_result)):?>
                <tr>
                    <td><?php echo $row['genNo'];?></td>
                    <td><?php echo $row['reliefNo'];?></td>
                    <td><?php echo $row['disas_date'];?></td>
                    <td><?php echo $row['area'];?></td>
                    <td><?php echo $row['city'];?></td>
                    <td><?php echo $row['type'];?></td>
                    <td><?php echo $row['surv_date'];?></td>
                    <td><?php echo $row['surv_volunteers'];?></td>
                    <td><?php echo $row['vol_incharge'];?></td>
                    <td><?php echo $row['relief_date'];?></td>
                    <td><?php echo $row['volunteers'];?></td>
                    <td><?php echo $row['venue'];?></td>
                    <td><?php echo $row['T_Beneficiary'];?></td>
                    <td><?php echo $row['unit'];?></td>
                    <td><?php echo $row['individual'];?></td>
                    <td><?php echo $row['house'];?></td>
                    <td><?php echo $row ['sacksNo'];?></td>
                    <td><?php echo $row ['DRG'];?></td>
                    <td><?php echo $row ['cost_set'];?></td>
                    <td><?php echo $row ['cost_relief'];?></td>
                    <td><?php echo $row ['DAI'];?></td>
                    <td><?php echo $row ['CAG'];?></td>
                    <td><?php echo $row ['TCA'];?></td>
                </tr>
                <?php endwhile;?>
            </table>
        </form>
        
    </body>
</html>





我尝试过:



我试图将$连接更改为$ con,将mysqli_query更改为mysql_query,遗憾的是错误仍然存​​在并且增加了更多。我不知道如何修复这个混乱以及如何在每个页面中添加分页时,当表格自动打10行时,将出现分页。我也知道当没有结果过滤器时如何显示消息无结果。



[由Nelek编辑]从非答案复制的其他信息下面

我使用的是php 4.0.1和Mysql版本5.5.54



What I have tried:

I tried to change $connection to $con and mysqli_query to mysql_query, unfortunately the error is still there and increased more. I don't know how I fix this mess and how I add pagination too in every page when table hit 10 rows automatic the pagination will appeared. and I know too how to show message "No Result" when there is no result in filter.

[edit by Nelek] Additional information copied from non answer below
And I'm using php version 4.0.1 and Mysql version 5.5.54

推荐答案

_POST ['search ')))
{
_POST['search'])) {


valueToSearch =
valueToSearch =


_POST ['valueToSearch'];
//在所有表格列中搜索
//使用concat mysql函数
_POST['valueToSearch']; // search in all table columns // using concat mysql function


这篇关于如何创建搜索/过滤表并添加分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆