我正在尝试编写一个 sql 来检查用户是否已达到每个类别的借用限制。
现在,它是使用几个相互调用的 sql 语句完成的。
但它的方法很简单。memId 和 id 来自查询字符串。
$medId = $_POST['memId']; Using 1 for this example. This is the members Id.
$id = $_POST['id']; Using 4 for this example. This is the item being lent.
之后我这样做:
select id, holder from collection_db where id = 4 // We have a valid item
select borrowMax from collection_db where id = (holder from the previous select) and category = 10 //Result = 2. Category indicates its a label and not a borrowable item.
select count(borrowedId) from lendings where memId = 1 and holder = (holder from the 1st query) //He's borrowed 2, under 1, so cant borrow any more. User 2 may borrow however.
if (count => borrowMax) {echo 'Cannot borrow more.';} else {echo 'Added to'}
如何将其组合成单个 sql 或者最好这样保留?