1

Hey guys im trying to get some data from a query (oracle) to pass into a varaible that i can use later in different fuctions/queries . can someone help me fix my code?

$conn = oci_connect('asdasddasddasd');
$RCB = array();

if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$stid = oci_parse($conn, "  SELECT WR.REQST_NO                          
                            FROM P_D.WORK_REQST WR                      
                            WHERE WR.WORK_REQST_STATUS_CD = 'PLAN' AND WR.DEPT_CD ='ISNG'       

                            ");
oci_execute($stid);



while (($row = oci_fetch_array($stid, OCI_BOTH+OCI_RETURN_NULLS)) != false) {
    // Use the uppercase column names for the associative array indices

$GLOBAL['RCB'] = $row['REQST_NO'];


}

print_r($RCB);

oci_free_statement($stid);
oci_close($conn);

how come this doesn't work?

1
  • $GLOBALS with an S... and you overwrite it each time, so just append a new row $GLOBALS['RCB'][] = $row['REQST_NO']; Commented Mar 3, 2017 at 19:16

2 Answers 2

1

You could use the while loop to build a new array.

i.e. :

$rcb_array = array();
while (($row = oci_fetch_array($stid, OCI_BOTH+OCI_RETURN_NULLS)) != false) {
    $rcb_array[] = $row['REQST_NO']; // for each $row, add a new item in $rcb_array with 'REQST_NO' value
}

print_r($rcb_array); // then use the new array outside the loop and do what ever you want with it

Hope it helps.

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

7 Comments

Glad to hear it. You're welcome. Thanks for validate this answer if it solved your question.
i have a part 2 to this problem, should i post here or make a new thread?
i couldn't post a new question so i edited this post.. any help would be appreciated
@DJRCB I feel that I've fallen onto deaf ears. I don't see a green tick next to this answer as you originally stated "thank you. this works! – DJRCB 39 mins ago" - Edit: you've accepted it ;-)
@JazZ welcome. Always glad to make the system work as it should and as it was written for ;-) Cheers
|
0

Try this one

while ($row = oci_fetch_assoc($stid)) 

{ $req_arr[] = $row['REQST_NO']; }

print_r($req_arr)

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.