从php Admin获取数据以供显示

时间:2017-12-28 07:22:41

标签: php html

我共有4本abc书。我在书籍详细页面中显示了作者1本书。我想在本书作者部分下面的其他书籍中展示剩余的3本作者书籍。但在本节中显示了该作者的一本书。请帮帮我,我该怎么办?

预订明细代码:

<?php   
    if(isset($_GET['pid']) && !empty($_GET['pid'])){
        $id = $_GET['pid'];

        $result = $conn->query("SELECT * FROM bookrecord WHERE id ='$id' and status='a'");

        if($result->num_rows > 0){
            $imgData = $result->fetch_assoc();
            extract($imgData);
                ?>
                    <div class="preview-pic tab-content">
                        <div class="tab-pane active" id="pic-1">                        
                            <img src="admin_pannel/book_images/<?php echo $imgData['file']; ?>" class="img-responsive" alt=""/>
                        </div>
                    </div>
                <?php
        }
    }
?>  

本作者代码的其他书籍:

<?php                           
    if(isset($_GET['auth_name']) && !empty($_GET['auth_name'])){
        $auth_name = $_GET['auth_name'];
        $result = $conn->query("SELECT * FROM bookrecord WHERE author_name ='$auth_name' and status='a'");

        if($result->num_rows > 0){
            $row = $result->fetch_assoc();
            extract($row);  
                ?>  
                    <div class="col-md-2">
                        <img src="admin_pannel/book_images/<?php echo $row['file']; ?>" class="img-responsive center-block">
                        <h4 class="text-center"><?php echo $row['book_title']; ?></h4>
                        <h5 class="text-center"><?php echo $row['author_name']; ?></h5>
                    </div>
                <?php
        }
    }   
?>  

这是我的(book-detail.php)页面,我来自这个链接:

<a class="btnpoem" href="book-detail.php?pid=<?php echo htmlentities($row['id']);?>&auth_name=<?php echo htmlentities($row['author_name']);?>">Download</a>

2 个答案:

答案 0 :(得分:1)

您需要在第二个代码中应用while(): -

<?php                           
    if(isset($_GET['auth_name']) && !empty($_GET['auth_name'])){
        $auth_name = $_GET['auth_name'];
        $result = $conn->query("SELECT * FROM bookrecord WHERE author_name ='$auth_name' and status='a'");

        if($result->num_rows > 0){
            while($row = $result->fetch_assoc()){
                extract($row);  
?>  
                <div class="col-md-2">
                    <img src="admin_pannel/book_images/<?php echo $row['file']; ?>" class="img-responsive center-block">
                    <h4 class="text-center"><?php echo $row['book_title']; ?></h4>
                    <h5 class="text-center"><?php echo $row['author_name']; ?></h5>
                </div>
<?php
            }
        }
    }
?>

注意: - {您的查询 Wide-Open {1}} 即可。  因此,请尝试使用 SQL-INJECTION

<强> 参考: -

PHP: mysqli::prepare - Manual

PHP: PDO::prepare - Manual

答案 1 :(得分:0)

只需从这段代码更改你的代码,在这段代码中你必须将你的sql查询改为ll位以获得除第一行之外的行,因为你有第一行(Image),而不是while循环你也可以使用foreach

   <?php                           
        if(isset($_GET['auth_name']) && !empty($_GET['auth_name'])){
            $auth_name = $_GET['auth_name'];
            $result = $conn->query("SELECT * FROM bookrecord WHERE author_name ='$auth_name' and status='a'" and WHERE ID NOT IN (SELECT MIN(ID) FROM your_table GROUP BY USER_ID));

            if($result->num_rows > 0){
                foreach ($result as $key){ 
    ?>  
                    <div class="col-md-2">
                        <img src="admin_pannel/book_images/<?php echo $key['file']; ?>" class="img-responsive center-block">
                        <h4 class="text-center"><?php echo $key['book_title']; ?></h4>
                        <h5 class="text-center"><?php echo $key['author_name']; ?></h5>
                    </div>
    <?php
                }
            }
        }
    ?>`