选择数组不显示结果


A Select Array Not Showing Results

我正在编写一个每天执行的 CRON 作业。 首先,它将从 MySql 表中识别字段"FAPforSale_repost35"中的日期,如果日期是今天的日期,它将执行命令删除目录中的照片图像,删除目录,最后从数据库中删除记录。

我正在第一步,即构建与日期日期匹配的记录数组。 当我运行代码时,没有错误,但即使测试表中的记录设置为今天,我也没有得到结果。 以下是选择

<?php
 define( "DIR", "../zabp_employee_benefits_processor_filesSm/", true );
 require( '../zipconfig.php' );
 require( DIR . 'lib/db.class.php' );
 require_once( $_SERVER['DOCUMENT_ROOT'] . '/_ZABP_merchants/configRecognition.php' );
 require_once( $_SERVER['DOCUMENT_ROOT'] . '/_ZABP_merchants/libRecognition/MailClass.inc' );

$todayRepost35 = date("Y-m-d");
echo $todayRepost35;

function repostEndSelect()
      {
        global $db;
    $this->db = $db;

     $data = $this->db->searchQuery( "SELECT `FAPforSale_IDnumber`,  `FAPforSale_image1`,  `FAPforSale_image2`,  `FAPforSale_image3`,  `FAPforSale_repost35`  FROM  `FAP_forSaleTest` Where `FAPforSale_repost35` = '$todayRepost35' ");

        $this->FAPforSale_IDnumber = $data[0]['FAPforSale_IDnumber'];
        $this->FAPforSale_image1 = $data[0]['FAPforSale_image1'];
        $this->FAPforSale_image2 = $data[0]['FAPforSale_image2'];
        $this->FAPforSale_image3 = $data[0]['FAPforSale_image3'];
        $this->FAPforSale_repost35 = $data[0]['FAPforSale_repost35'];
        echo $this->FAPforSale_IDnumber;
        echo $this->FAPforSale_image1;
        echo $this->FAPforSale_image2;
        echo $this->FAPforSale_image3;
        echo $this->FAPforSale_repost35;
    } // ends function...
echo( ' Finished...' );
?>

提前感谢您的任何建议或指导。

$todayRepost35超出了函数的范围。您必须将其范围限定为函数,或将其作为参数传递(后者是更好的主意(:

function repostEndSelect() {
    global $db;
    global $todayRepost35;
    // ...
}

或:

function repostEndSelect($todayRepost35) {
    global $db;
    // ...
}
// ...
$test = repostEndSelect($todayRepost35);

此外,在函数中使用$this将不起作用。如果函数是类的一部分,并且您(出于某种原因(没有包含类定义,则忽略它。