我有一个查询
$query = "INSERT INTO `user`
(`fname`,
`lname`,
`email`,
`password`,
`permission`,
`idcustomer`)
VALUES
(
'" . $firstname . "',
'" . $lastname . "',
'" . $email . "',
'" . $password . "',
'admin',
" . $idcustomer . "
);";
现在,我只需要执行此查询,下面的查询结果是> 0:
select (number_of_users - (select count(*) from user where idcustomer=2)) availableUsers
from customer where idcustomer=2
答案 0 :(得分:1)
只需使用select
代替values(...)
:
$query = "INSERT INTO `user`
(`fname`,
`lname`,
`email`,
`password`,
`permission`,
`idcustomer`)
select
'" . $firstname . "',
'" . $lastname . "',
'" . $email . "',
'" . $password . "',
'admin',
" . $idcustomer . "
from customer
where idcustomer = 2
and (number_of_users - (select count(*) from user where idcustomer=2)) > 0
);";