I have a sql query and I want it to also only show the information for the logged in user. I was thinking is it possible for me to add another where clause to the query to add in: username = ‘”.$_SESSION[‘login_user’].”‘
Here is my query:
$sql= "
SELECT
user.username,books.bid,name,authors,edition,
status,approve,issue,issue_book.return
FROM user
inner join issue_book ON user.username=issue_book.username
inner join books ON issue_book.bid=books.bid
WHERE issue_book.approve ='$exp'
ORDER BY `issue_book`.`return` DESC";
Anyone know how I would write this to achieve what I want above?
Here is my entire code:
<!-- Updated navbar for logged in user -->
<?php
if($_SESSION['login_user'])
{
include "navbar_user.php";
}
?>
<h2 style = "text-align: center; padding: 2%;">Your Expired Books </h2>
<?php
if(isset($_SESSION['login_user']))
{
$exp = 'EXPIRED';
$session_value = $_SESSION['login_user'];
$sql= "SELECT user.username,books.bid,name,authors,edition,status,approve,issue,issue_book.return FROM user inner join issue_book
ON user.username=issue_book.username inner join books ON issue_book.bid=books.bid WHERE issue_book.approve ='$exp' AND username = ".$_SESSION['login_user']."
ORDER BY `issue_book`.`return` DESC";
$res = mysqli_query($db,$sql);
if(mysqli_num_rows($res)==0)
{
echo "You have no expired books.";
}
else
{
?>
<table class = 'table table-bordered'>
<tr style='background-color: #abb79b; color: white;'>
<th>Username</th>
<th>BID</th>
<th>Book Name</th>
<th>Authors Name</th>
<th>Edition</th>
<th>Status</th>
<th>Return Date</th>
</tr>
<?php
while ($row = mysqli_fetch_assoc($res)) {
?>
<tr style = 'background-color: white;'>
<td><?php echo $row['username'] ?></td>
<td><?php echo $row['bid'] ?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['authors'] ?></td>
<td><?php echo $row['edition'] ?></td>
<td><?php echo $row['status'] ?></td>
<td><?php echo $row['return'] ?></td>
</tr>
<?php
}
}
}
else
{
echo "</br></br></br>";
echo "<h2><b>";
echo "Please login first.";
echo "</b></h2>";
}
?>
</table>