0

質問があります

$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
4

1 に答える 1

1

selectの代わりにa を使用して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
    );";
于 2012-10-29T21:45:00.910 に答える