分页中的PDO问题

时间:2017-11-16 07:35:49

标签: php html mysql pdo

这是以PDO格式转换的分页代码,这不会给出连接到表的任何输出,这里是pdo分页代码的代码

<?php               
                 $total_num_page=2;
               if (isset($_GET['page']))
                    {
                        $page_id = $_GET['page'];
                    } 
               else
                    {
                        $page_id = 1;
                    }
                    $search = '' ;
                    if( isset($_POST['search']) )
                    {
                        $search = urldecode($_POST['search']);
                    }
                    else if( isset($_GET['search']) ) 
                    {
                        $search = urldecode($_GET['search']);
                    }
              if ($search)
              {
                        $all_stmt=$db->prepare("select * from files where recieved_by like :needle or processed_by like  :needle or   purpose like :needle or file_name like  :needle order by date desc");
                        $needle = '%' . $search . '%';
                        $all_stmt->bindValue(':needle', $needle, PDO::PARAM_STR);  
                        $all_stmt->execute();
                        $all_post=$all_stmt->rowCount();
                        $total_page = ceil($all_post / $total_num_page);
                        $page_start_from = ($page_id - 1) * $total_num_page;
              } 
               else 
               {
                    $all_post_query = "select * from files order by date desc";
                    $all_stmt=$db->prepare($all_post_query);
                    $all_stmt->execute();
                    $all_post=$all_stmt->rowCount();
                    $total_page = ceil($all_post / $total_num_page);
                    $page_start_from = ($page_id - 1) * $total_num_page;
               } 
               ?>

这是我从表数据库中获取数据的部分,我不知道会出现什么问题,

  <?php
                             if ($search)
                            {
                                $stmt=$con->prepare("select * from files where recieved_by like :needle or processed_by like  :needle or  purpose like  :needle or file_name like :needle order by date desc limit $page_start_from, $total_num_page"); $needle = '%$search%';
                                $stmt->bindValue(':needle', $needle, PDO::PARAM_STR);  
                            } 
                            else 
                            {
                                $stmt=$con->prepare("select * from files order by date desc limit $page_start_from, $total_num_page");
                            }
                            $stmt->execute();
                            $stmt->fetchAll();
                            if(count($stmt)>0){
                            while($row=$stmt->fetch())
                             {
                                $c_id=$row['id'];
                                $file=$row['file_name'];
                                $purpose=$row['purpose'];
                                $recieve=$row['recieved_by'];
                                $processed=$row['processed_by'];
                                $address=$row['address'];
                                $contact=$row['contact_no'];
                                $date=$row['date'];


                            ?>
                                            <tr>

                                                <td><a  href="post.php?post_id=<?php echo $c_id?>"><?php echo $c_id;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $file;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $purpose;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $recieve;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $processed;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $address;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $contact;?></a></td>
                                                <td><a href="post.php?post_id=<?php echo $c_id?>"><?php echo $date;?></a></td>
                                            </tr>
                                            <?php 
                                      }
                            }
                                            else
                                            {
                                                echo "No Related File Found Here ";
                                            }

                                   ?>
                                        </tbody>
                                    </table>
                <nav id="pagination">
    <ul class="pagination">
        <?php
        $search_str = '';
        if ($search) {
            $search_str = "&search=" . urlencode($search);
        }
        for ($i = 1; $i <= $total_page; $i++)
            echo "<li class='" . ($page_id == $i ? 'active' : '') . "'><a href='index.php?page=" . $i . $search_str . "'>$i</a></li>";
        ?>

这是我的数据库代码

<?php
$servername = "localhost";
$username = "root";
$password = "";
    $con = new PDO("mysql:host=$servername;dbname=fileprogramsysteeem", $username, $password);
?>

我也想检查一下,如果在页面中没有找到相关页面的条件,它应该显示其他输出,现在我做错了什么可以请任何人帮助我

  

此处未找到相关文件

0 个答案:

没有答案