I have two values in an array that I want to have show up in a string variable that 开发者_运维技巧I am building. Theses values are dynamic and are subject to change, so I want to be able to build the string straight from the array. I thought I was on the right track but the values are not showing up.
My Code:
$range = "WHERE transdate >= \"{$halfway['startdate']}\" AND transdate <= \"{$halfway['enddate']}\"";
The output:
WHERE transdate >= "" AND transdate <= ""
The following works for me in php 5.3.5 cli. I haven't modified your string
$halfway = array(
'startdate' => 'somedate',
'enddate' => 'otherdate'
);
$range = "WHERE transdate >= \"{$halfway['startdate']}\" AND transdate <= \"{$halfway['enddate']}\"";
print $range;
Output:
WHERE transdate >= "somedate" AND transdate <= "otherdate"
Check that $halfway
actually has data.
Try removing the quotes in the array element.. I think that would work..
WHERE transdate >= \"{$halfway[startdate]}\" AND transdate <= \"{$halfway[enddate]}\"
Why do you use a framework and not use its ORM?
$this->ModelName->find('all', array(
'conditions' => array(
'ModelName.transdate BETWEEN ? AND ?' => array(
$halfway['startdate'],
$halfway['enddate']
)
)
));
精彩评论