0

I need to run a query and save the values in a PHP array. So that in the later time, I could pass the array into json and even run sizeof() for data manipulation. so far my query is this,

   WITH DATA
     AS (SELECT TO_DATE ('2012-01-02', 'YYYY-MM-DD') date1,
                TO_DATE ('2012-02-20', 'YYYY-MM-DD') date2
           FROM DUAL)
 SELECT TO_CHAR (date1 + LEVEL - 1) datename,
        TO_CHAR (date1 + LEVEL - 1, 'fmMonth') month_name,
        TO_CHAR (date1 + LEVEL - 1, 'IW') the_week,
        TO_CHAR (date1 + LEVEL - 1, 'D') the_day,
        TO_CHAR (date1 + LEVEL - 1, 'DAY') the_day_name
   FROM data
CONNECT BY LEVEL <= date2 - date1 + 1

and the php is,

$days = array();
            while ($row = oci_fetch_array($dateHeaderParse)){ 
                $days = $row['THE_DAY'];
            }
            ?>

and when i execute withthis,

    print_r($days);

its only returning two, which supposed to be more than two. The query is perfectly working.

Please help me

2
  • 1
    You're using $days = $row['THE_DAY']; - shouldn't it be array_push($days, $row['THE_DAY']);? Commented Apr 16, 2015 at 2:30
  • thank you, can you post the answer again so i can make it an answer ? Commented Apr 16, 2015 at 2:57

1 Answer 1

1

Your problem is that when you loop through the results from oci_fetch_array, you're setting $days to the current result, and discarding the previous value. You should actually be appending the results into $days like this:

$days = array();
while ($row = oci_fetch_array($dateHeaderParse)){ 
    array_push($days, $row['THE_DAY']);
}

I'm not a PHP developer, so this may not work, but you may be able to do this using oci_fetch_all and array_map, like this:

$days = array_map(function($row) {return $row['THE_DAY'];},
    oci_fetch_all($dateHeaderParse));
Sign up to request clarification or add additional context in comments.

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.