skip to Main Content

I have this query that will find a specific borrowDetail when i tried value 2 it does return data
it does return data

from me but when i tried to find the 1 it does not give any data.
no data

SELECT bd.BorrowDetails_ID, b.User_ID, 
        b.Accession_Code, bk.Book_Title, bd.Quantity, b.Date_Borrowed, 
        b.Due_Date, br.Borrower_ID, bd.tb_status
        FROM
        tbl_borrowdetails AS bd
        INNER JOIN
        tbl_borrow AS b ON bd.Borrower_ID = b.Borrow_ID
        INNER JOIN
        tbl_books AS bk ON b.Accession_Code = bk.Accession_Code
        INNER JOIN
        tbl_borrower AS br ON b.Borrower_ID = br.Borrower_ID
                WHERE   bd.BorrowDetails_ID = 21

tb_borrow

tbl_borrowdetails

tbl_borrower

tbl_books

then this is my query builder

enter image description here

on the borrower table it does have the data that i inserted on the other page, it registered and was distributed too on the other page, but when i call it in this return page, it does not work only the value 2 work,

i have tried to revise the query yet no success. it kept getting NO record found on the


// Check if the borrowId parameter is set in the URL
if(isset($_GET['borrowId'])) {
    // Set the session variable after sanitizing it
    $_SESSION['BorrowDetails_ID'] = filter_var($_GET['borrowId'], FILTER_SANITIZE_STRING);
    // Optionally, you can redirect back to the same page or perform any other action
    header("Location: staff_return_transaction.php");
    exit();
}

// Initialize $bd_Id to an empty string
$bd_Id = $_SESSION['BorrowDetails_ID'];


        // Prepare the SQL statement with a placeholder for the search input
        $sql = "SELECT bd.BorrowDetails_ID, b.User_ID, 
        b.Accession_Code, bk.Book_Title, bd.Quantity, b.Date_Borrowed, 
        b.Due_Date, br.Borrower_ID, bd.tb_status
        FROM
        tbl_borrowdetails AS bd
        INNER JOIN
        tbl_borrow AS b ON bd.Borrower_ID = b.Borrow_ID
        INNER JOIN
        tbl_books AS bk ON b.Accession_Code = bk.Accession_Code
        INNER JOIN
        tbl_borrower AS br ON b.Borrower_ID = br.Borrower_ID
                WHERE   bd.BorrowDetails_ID = $bd_Id";



PLease do help me find what is wrong with my query as why it returns a value to me when i try 2 and why it does not return value when i ask for 1

2

Answers


  1. Chosen as BEST ANSWER
    WHERE
    b.Borrow_ID = 2;
    

    i just changeg the target to borrow_ID from borrowDetails, i just found out that my where statement is the one that provides me with the wrong answer


  2. INNER JOIN   tbl_borrow AS b ON bd.Borrower_ID = b.Borrow_ID 
    

    should be

    INNER JOIN   tbl_borrow AS b ON bd.Borrower_ID = b.Borrower_ID
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search