如何在Mysql中传递php变量选择Query

时间:2012-08-09 05:52:16

标签: php

$valid是一个数组,$createdon$days从数组中获取Date值。  我的选择查询不适用于PHP变量的这些日期值,请解决它。

function checkexpiretime($valid)
    {
        $db = &JFactory::getDBO();
        foreach($valid as $validity)
        {
             echo $createdon=$validity->CreatedOn;
             echo $days=$validity->days;
        }
        echo $query="SELECT * FROM jos_generatekey WHERE CreatedOn BETWEEN DATE_ADD('".$createdon."',".INTERVAL $days DAY.")". "AND CURDATE()"; 
        $db->setQuery($query);
        $checkexpire = $db->loadObjectList();
        print_r($checkexpire);
        return $checkexpire;
    }

1 个答案:

答案 0 :(得分:0)

查询应该是这样的:

$query= "SELECT * FROM jos_generatekey WHERE CreatedOn BETWEEN DATE_ADD('".$createdon."',INTERVAL ". $days ." DAY) AND CURDATE()";