Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 若表的记录为空,则不应发送电子邮件_Php_Oracle - Fatal编程技术网

Php 若表的记录为空,则不应发送电子邮件

Php 若表的记录为空,则不应发送电子邮件,php,oracle,Php,Oracle,我在一个PHP项目工作,我需要发送数据的表格,一些收件人只有在表中有记录,否则电子邮件不应该被发送 请纠正我的“如果”条件,因为我是php新手 // if record is null then email should not be sent. $sql="SELECT * FROM tmp_Roshan_line T "; $result = odbc_exec($connect_cc, $sql) or die("Couldn't execute query! ".o

我在一个PHP项目工作,我需要发送数据的表格,一些收件人只有在表中有记录,否则电子邮件不应该被发送

请纠正我的“如果”条件,因为我是php新手

 // if record is null then email should not be sent.
     $sql="SELECT * FROM tmp_Roshan_line T ";
     $result = odbc_exec($connect_cc, $sql) or die("Couldn't execute query! ".odbc_errormsg());

      if ($result!=NULL){

//Sending Email
$htmlbody ="
<head>
<style>
table {
    border-collapse: collapse;
    border: 0px;
    width: 20%;
}

th, td {
    text-align: left;
    padding: 3px;
    font-size:12px;
    border: 0px;
}

tr:nth-child(even){background-color: #f2f2f2}

th {
    background-color: #68a936;
    color: Black;
    border: 0px;
}
</style>
</head>";
$htmlbody .= "<p style='font-size:14;'>Dear Roshan Team,<br><br>
Following lines are dedected as 100% simbox lines by our detection tool, please block them and confirm with us. <b>"."</b></p><br><br>";



$htmlbody .= "
检索记录 odbc_fetch_row函数用于从结果集中返回记录。如果该函数能够返回行,则返回true,否则返回false

$sql="SELECT * FROM tmp_Roshan_line T";
$rs=odbc_exec($connect_cc,$sql);
if (!$rs)
  {
  exit("Error in SQL");
  }


while (odbc_fetch_row($rs))
{

 //Sending Email
$htmlbody ="
<head>
<style>
table {
    border-collapse: collapse;
    border: 0px;
    width: 20%;
}

th, td {
    text-align: left;
    padding: 3px;
    font-size:12px;
    border: 0px;
}

tr:nth-child(even){background-color: #f2f2f2}

th {
    background-color: #68a936;
    color: Black;
    border: 0px;
}
</style>
</head>";
$htmlbody .= "<p style='font-size:14;'>Dear Roshan Team,<br><br>
Following lines are dedected as 100% simbox lines by our detection tool, please block them and confirm with us. <b>"."</b></p><br><br>";


// send email code 
}
odbc_close($conn);

您可以简单地检查条件,而无需将其与NULL进行比较

if ($result){
   # condition goes here
 }
或者,如果您真的想根据空值检查它,您可以这样做 通过使用php函数

使用


只有在运行查询时出错时,orbc_exec才会返回false。即使在查询执行过程中没有结果,也会返回true。最好的方法是计算返回的行数。为此,您需要使用[odbc\u num\u rows][1]

使用if$result,这应该是可行的!
if (!is_null($result)) {
   # condition goes here
}
if (odbc_num_rows($result)>0){
 //send mail
  }
else{
      //dont send mail
    }