0

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 <= ""
1
  • 1
    i hope you escape your array beforehand Commented Jun 3, 2011 at 16:37

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

wow...haha. I was building the string before the array. Thanks
1

Try removing the quotes in the array element.. I think that would work..

WHERE transdate >= \"{$halfway[startdate]}\" AND transdate <= \"{$halfway[enddate]}\"

3 Comments

According to my testing, either should work. Tells me it's something wrong with the $halfway object.
"WHERE transdate >= '$halfway[startdate]' AND transdate <= '$halfway[enddate]'"; How about that?
Yeah this works too, I was building the string before halfway so the values were not showing up.
0

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']
         )
    )
));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.