duanbei2914 2017-02-24 00:05
浏览 30

有mysql查询的困难

Image. I've been working on this app and I have some minor problems. The basic one, where everything goes on further, is the MySQL query. I'll put the code and I will upload the picture for you to see the outcome of this problem. So basically I want the query to show only results that are from that "id" I got from GET method. Therefore, it prints every single thing from databasem doesn't matter which id. But the column of those who are not as the GET "id", are blank. I would like them to disappear and to show only that match up with get id Thank you in advance.

<?php
require_once 'requires/dbconnect.php';
require_once 'requires/session.php';
require_once "requires/head.php";
require_once 'requires/navbar.php';

$id = $_GET['id'];

$query = $DBcon->query("SELECT * FROM borrow
                            LEFT JOIN users ON borrow.member_id = users.id   AND borrow.member_id = '$id'
                            LEFT JOIN borrowdetails ON borrow.borrow_id = borrowdetails.borrow_id AND borrowdetails.member_id = '$id'
                            LEFT JOIN book ON borrowdetails.book_id =  book.book_id
                            ORDER BY borrow.borrow_id DESC");
    ?>
    <div class="container">
    <table class="table table-hover table-bordered">
    <tr class="active">
        <td><b>Book Title</b></td>
        <td><b>Username</b></td>
        <td><b>Date Borrowed</b></td>
        <td><b>Date Returned</b></td>
        <td><b>Status</b></td>
        <td></td>
    </tr>
    <tr>
    <?php
    while ($row = $query->fetch_array()) {
        $id                = $row['borrow_id'];
        $member_id         = $row['member_id'];
        $book_id           = $row['book_id'];
        $borrow_details_id = $row['borrow_details_id'];
        ?>
                                <td><a href="bookbrief.php?id=<?php echo $book_id; ?>"><?php echo $row['book_title']; ?></a></td>
                                <td><a href="profile.php?id=<?php echo $member_id; ?>"><?php echo $row['username']; ?></a></td>
                                <td><?php echo $row['date_borrow']; ?></td> 
                                <td><?php echo $row['date_return']; ?> </td>
                                <td><?php echo $row['borrow_status'];?></td>
                                <?php
                                if($row['borrow_status'] == 'pending')
                                { ?>
                                    <td class="danger">Pending</td>
                                <?php }
                                else if ($row['borrow_status'] == 'returned') { ?>
                                    <td class="success">Returned</td>
                                <?php } ?> 

                                </tr>
    <?php } ?>
    </table>
    </div>`
  • 写回答

1条回答 默认 最新

  • doumou8527 2017-02-24 00:31
    关注

    I don't see a WHERE clause after all of your JOINs.

    WHERE borrow.member_id=$id;
    

    (This is NOT literally what you should write into your query. You'll need to validate/sanitize/parameterize the $_GET for security reasons.)

    For your case, this time, you can get away with sanitizing like this prior to putting it in the query:

    $id = intval($_GET['id']);
    

    ...but definitely read up on parameterization.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?