选择不显示结果的数组

时间:2014-12-21 22:32:31

标签: php arrays select

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

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

<?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...' );

?>

提前感谢任何建议或指示。

1 个答案:

答案 0 :(得分:0)

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

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

或者:

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

此外,在函数内部使用$this将无效。如果函数是类的一部分,并且(由于某种原因)你没有包含类定义,那么忽略它。