Skip to content

Commit 9b7302a

Browse files
fixing the book available logic
1 parent 94d985c commit 9b7302a

File tree

4 files changed

+19
-38
lines changed

4 files changed

+19
-38
lines changed

all.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<table width="853" border="0" cellspacing="1" style=" margin-left:15px;background:#F90;font-size:12px; font-family:Verdana, Geneva, sans-serif;">
66
<?php
77
include('database/config.php');
8-
$q="select b.book_id, title, author_name, branch_name, no_of_copies, no_issued, (no_issued + no_of_copies) AS no_total from book b
8+
$q="select b.book_id, title, author_name, branch_name, no_of_copies, IFNULL(no_issued, 0) AS no_issued, (no_of_copies- IFNULL(no_issued, 0)) AS no_available from book b
99
join book_authors ba on b.book_id = ba.book_id
1010
join book_copies bc on b.book_id=bc.book_id
1111
join library_branch lc on bc.branch_id = lc.branch_id
12-
join (SELECT book_id, count(*) AS no_issued FROM book_loans GROUP BY book_id) book_issues ON book_issues.book_id = b.book_id
12+
LEFT join (SELECT book_id, branch_id, count(*) AS no_issued FROM book_loans WHERE date_in = '0000-00-00' GROUP BY book_id, branch_id) book_issues ON book_issues.book_id = b.book_id AND lc.branch_id = book_issues.branch_id
1313
order by b.book_id;
1414
";
1515
$rs=mysql_query($q);
@@ -27,10 +27,10 @@
2727
<td width="120"><?php echo $row['author_name']; ?></td>
2828
<td width="120"><?php echo $row['branch_name']; ?></td>
2929
<td width="50" >
30-
<input readonly="readonly" type="text" style="background:#FFF;padding:2px; width:20px;" value="<?php echo $row['no_total'];;
30+
<input readonly="readonly" type="text" style="background:#FFF;padding:2px; width:20px;" value="<?php echo $row['no_of_copies'];;
3131
?>"/></td>
3232
<td width="50" >
33-
<input readonly="readonly" type="text" style="background:#FFF;padding:2px; width:20px;" value="<?php echo $row['no_of_copies'];;
33+
<input readonly="readonly" type="text" style="background:#FFF;padding:2px; width:20px;" value="<?php echo $row['no_available'];;
3434
?>"/></td>
3535
<td class="view">
3636
<a href="?addBooks&book_id=<?php echo $row['book_id'] ?>&view">View</a></td>

borrowBooks.php

+1-20
Original file line numberDiff line numberDiff line change
@@ -452,33 +452,14 @@ function timing()
452452
$rs_update=mysql_query($sql);
453453
if($rs_update){
454454

455-
456-
$upd="select * from book_copies where book_id='".$_GET['accNo']."'";
457-
$obj = mysql_query($upd);
458-
$cop=mysql_fetch_array($obj);
459-
460-
if(isset($_GET['accNo'])){
461-
462-
$get=$cop['no_of_copies']-1;
463-
}else{
464-
465-
$get=$copy-1;
466-
}
467-
468-
$update="update book_copies set no_of_copies='$get' where book_id='$accNo'";
469-
$objExec = mysql_query($update);
470-
if($objExec){
471-
?>
472-
455+
?>
473456
<script>
474457
$(document).ready(function(){
475458
$("#success").fadeIn(1000);
476459
});
477460
</script>
478461
<?php
479462
//echo "Your Borrow has been Registered";
480-
}
481-
482463

483464
}
484465
}

returnbookpopup.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ function printDiv(divID) {
395395
$query12 = "select * from book where book_id=$name[book_id]";
396396
$s=mysql_query($query12);
397397
$boks=mysql_fetch_array($s);
398-
$add=$boks['bookcopies']+1;
399398
?>
400399
<?php
401400

@@ -481,16 +480,14 @@ function printDiv(divID) {
481480

482481
$update2="update tblborrow set datereturn='$re',item='0', status='Signed' where borrowid='$id'";
483482
$objExec2 = mysql_query($update2)or die(mysql_error());
484-
if($objExec2){
485-
$up2="update books set bookcopies='$add' where accNo='".$boks['accNo']."'";
486-
mysql_query($up2)or die(mysql_error());?>
483+
484+
?>
487485
<script>
488486
$(document).ready(function(){
489487
$("#div2").fadeIn(1000);
490488
});
491489
</script>
492490
<?php
493-
}
494491
}
495492
}
496493
?>

search.php

+12-9
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
$q=$_POST['searchword'];
1515

16-
$sql_res="select b.book_id, title, author_name, branch_name, no_of_copies from book b
16+
$sql_res="select b.book_id, title, author_name, branch_name, no_of_copies, IFNULL(no_issued, 0) AS no_issued, (no_of_copies- IFNULL(no_issued, 0)) AS no_available from book b
1717
join book_authors ba on b.book_id = ba.book_id
1818
join book_copies bc on b.book_id=bc.book_id
1919
join library_branch lc on bc.branch_id = lc.branch_id
20-
20+
LEFT join (SELECT book_id, branch_id, count(*) AS no_issued FROM book_loans WHERE date_in = '0000-00-00' GROUP BY book_id, branch_id) book_issues ON book_issues.book_id = b.book_id AND lc.branch_id = book_issues.branch_id
2121
where b.book_id like '%$q%' or title like '%$q%' or author_name like '%$q%'
2222
order by b.book_id";
2323

@@ -27,27 +27,30 @@
2727
$items = 0;
2828
?>
2929

30-
30+
3131
<?php while($row=mysql_fetch_array($r))
3232
{
33-
$items++;
33+
$items++;
3434
$bookid=$row['book_id'];
3535
$booktitle=$row['title'];
3636
$author=$row['author_name'];
3737
$branch=$row['branch_name'];
3838
$copies=$row['no_of_copies'];
39+
$available = $row['no_available'];
3940

4041
$re_bookid='<b>'.$q.'</b>';
4142
$re_booktitle='<b>'.$q.'</b>';
4243
$rauthor='<b>'.$q.'</b>';
4344
$rbranch='<b>'.$q.'</b>';
4445
$rcopies='<b>'.$q.'</b>';
46+
$ravailable='<b>'.$q.'</b>';
4547

4648
$f_bookid = str_ireplace($q, $re_bookid, $bookid);
4749
$fbooktitle = str_ireplace($q, $re_booktitle, $booktitle);
4850
$fauthor = str_ireplace($q, $rauthor, $author);
4951
$fbranch = str_ireplace($q, $rbranch, $branch);
5052
$fcopies = str_ireplace($q, $rcopies, $copies);
53+
$favailable = str_ireplace($q, $ravailable, $available);
5154
?>
5255

5356

@@ -66,7 +69,7 @@
6669
<input readonly="readonly" type="text" style="background:#FFF;padding:2px; width:50px;" value="<?php echo $fcopies;
6770
?>"/></td>
6871
<td width="50" >
69-
<input readonly="readonly" type="text" style="background:#FFF;padding:2px; width:50px;" value="<?php echo $fcopies;
72+
<input readonly="readonly" type="text" style="background:#FFF;padding:2px; width:50px;" value="<?php echo $favailable;
7073
?>"/></td>
7174

7275
<td class="view" width="35">
@@ -77,8 +80,8 @@
7780
<td class="del">
7881
<?php echo '<div align="center"><a href="#" id="'.$row['book_id'].'" class="delbutton" >Delete</a></div>'; ?>
7982
</td>
80-
81-
83+
84+
8285
</tr>
8386

8487

@@ -98,7 +101,7 @@
98101
Search Not Found</div>
99102

100103
<?php }
101-
104+
102105
}
103106

104107
?>
@@ -125,7 +128,7 @@
125128
url: "delete.php",
126129
data: info,
127130
success: function(){
128-
131+
129132
}
130133
});
131134
$(this).parents(".hr").animate({ backgroundColor: "#fbc7c7" }, "fast")

0 commit comments

Comments
 (0)