这只是为了展示它是如何完成的。您应该使用 MySQLi 或 PDO 。此外,如果在生产环境中,您不应该向用户显示 MySQL 错误。
你可以这样做:
// SQL to find Available value for Item Mouse
$sql = "SELECT Item, Available FROM accessories_other
WHERE Item = 'Mouse'";
$result = mysql_query( $sql ) or die( 'Query failed.'.mysql_error() );
$row = mysql_fetch_array( $result ) ;
if( mysql_num_rows( $result ) > 0 )
{
echo $row['Item'] ,': ' ,$row['Available'];
if( $row['Available'] < 5 )
{
// Code to send email
}
else
{
// Code to what ever you would like to do here
}
}
或者
// SQL to find Available value for Item Mouse if it is less than 5
$sql = "SELECT Item, Available FROM accessories_other
WHERE Item = 'Mouse' AND Available < 5";
$result = mysql_query( $sql ) or die( 'Query failed.'.mysql_error() );
if( mysql_num_rows( $result ) > 0 )
{
// Code to what ever you would like to do here
}
else
{
echo $row['Item'] ,': ' ,$row['Available'];
// Code to send email
}