停止将值插入表中

时间:2018-05-09 04:42:37

标签: php mysql

我有两张桌子。一个是项目表,另一个是问题表。 问题表使用对item_id的外键引用。

我正在使用问题表向我的员工发放项目,并将项目数量扣除到我的项目表。没有问题发出项目和扣除项目表上的数量,我想要的是当数量变为零时,员工姓名将停止向问题表插入值。因为每次我试图发出值都插入问题表中,即使项目表中的数量为零。

if row is greater than zero, do not proceed. else insert it to this table.
希望你明白。

2 个答案:

答案 0 :(得分:0)

...粗略地

Protocol   Top domain   URL

           com          somedomain.com/my%20folder/my%20page.html 
http       info         http://somedomain.info/my%20folder/ 
https      com          https://somedomain.com/my%20folder/ 
http       com          http://www.somedomain.com/my%20folder/ 
https      info         https://www.somedomain.info/my%20folder/ 
           com          somedomain.com/my%20folder/ 
http       com          http://www.somedomain.com/my%20folder/sub.folder/directory/ 
https      info         https://www.somedomain.info/my%20folder/ 
           com          somedomain.com/my%20folder/ 
           tv           somedomain.tv 

答案 1 :(得分:-1)

$con=mysqli_connect(SERVER, DBUSER, DBPASS, DATABASE);

// Check connection
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT quantity FROM item  WHERE item_id = 1;";
$result = mysqli_query($con,$sql);

$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
if($row["quantity"] > 0) {
    //insert
}