Okay so I've searched just about everywhere but can't seem to find what I'm looking for. I'm learning as I go with PHP and I'm having a problem figuring out what is wrong.

I've got two different queries calling a group of information. Within each query is a field that is the same. I want to use an if statement to pull another field comparing the two identical fields. The if statement is the only problem in the code. Everything else works fine. I'm not even sure this is possible.

Here is the piece that is the problem:

if ($row['id'] == $dec['id'])
        { 
          echo "<td>".$dec['apdc_code']."</td>";
        }

Like I said this is the only piece with a problem, so I didn't post the whole code. Is this possible? Am I missing something? Any help would be great! Thanks!

The statement itself looks fine.
So I would need to see the surrounding code in order to tell you why it is not working.
Also, what is not working, does row ever == dec[id]?
is it getting evaluated at all? put an else in with an echo to see if it is ever true.
My initial guess is that you are not holding the "$dec" value at this point in your script.
If you are looping through a result set, or both (I assume row is query1 data and dec is query2 data)
you will only hold that first value that is in result... I am speculating at this point, please post your whole function and I will see if I can't resolve your issue.

So it would seem that the IF statement isn't being evaluated as you guessed.
The row and dec should contain identical values. I even modified the query associated with dec to where it is almost an exact copy of the row one with the slight change I need to pull that additional piece of information. Would some sort of count with the loop solve the problem?

while($row = oci_fetch_array($result))
    {
        $dQuery = "select 
              sarappd_apdc_code
            from 
	             spriden,
	             saradap,
               sarappd
             where
               saradap_program_1 like '%'
              and
	              saradap_pidm = ".$row['SPRIDEN_PIDM']."
              and 
                spriden_pidm = sarappd_pidm 
              and
              	saradap_apst_code = 'C'
              and 
              	saradap_term_code_entry in ('201102')
              and
              	saradap_levl_code = '02'
             and
                sarappd_apdc_code in (select sarappd_apdc_code from sarappd
                where spriden_pidm = sarappd_pidm
                and saradap_term_code_entry = '201102'
                and sarappd_apdc_date in (select max(sarappd_apdc_date) 
                                          from sarappd
                                          where spriden_pidm = sarappd_pidm))
             and
              	spriden_change_ind is null";
                                    
        $dResults = oci_parse($conn, $dQuery);
        oci_execute($dResults);
        $dec = oci_fetch_array($dResults); 
            
            if ($row['spriden_id'] == $dec['spriden_id'])
          { 
            $decision = $dec['sarappd_apdc_code'];
          }
          else
          {
            $decision = "I'm not here...";            
          }

this is the bulk of it minus the row query...but as I said it's almost identical.

I haven't used oci_fetch_array in a while, so I am not 100% sure about its behavior, but lets start with your $dQuery itself. You are not selecting spriden_id only:

$dQuery = "select
sarappd_apdc_code        <======
from
spriden,
saradap,
sarappd

change to:
$dQuery = "select
sarappd_apdc_code,spriden_id        <======
from
spriden,
saradap,
sarappd

the rest of it looked ok at this point, so change your query to pull that id and see if your not fixed. ( that may not be the exact 'correct' syntax to fix your query but it appears to me as though you are not pulling that id)

Oh good grief...I copied that off of an old one I was working with. Sorry about that.
The current one does have that change in it and I am still not getting the apdc_code to output. Everything else is coming out just fine.
Any other suggestions? Still think it has something to do with what you suggested earlier but I can't put my finger on how to fix it.

I'd start with some debugging code.
try a print_r($dec) or var_dump($dec)
do you have expected data / variables?
another thought is that possibly $dec has more than 1 row in it throwing off any comparison code you might be trying to run on it. Is it possible that your $dec may be at location $dec[0]->spriden_id or some other name in your $dec array.
at that point in your code does $row have your expected value?
possibly set a variable ? $sid = $row at top of while loop and just grab that $sid for comparison later. The main question is what is in $dec, right before your comparison if statement.

I'd start with some debugging code.
try a print_r($dec) or var_dump($dec)
do you have expected data / variables?

Alright, this helped me track down a problem in the actual query that I hadn't noticed but I got that cleaned up. Now I get exactly what I would expect from the query results.

another thought is that possibly $dec has more than 1 row in it throwing off any comparison code you might be trying to run on it. Is it possible that your $dec may be at location $dec[0]->spriden_id or some other name in your $dec array.

It appears to function correctly but I'm not 100% sure what I'm looking at or potential issues. I may not be seeing something I should. Here is what I get when I use print_r($dec).

Array ( [0] => 4392 [SPRIDEN_ID] => 4392 [1] => 00 [SARAPPD_APDC_CODE] => 00 )              
Array ( [0] => 8471 [SPRIDEN_ID] => 8471 [1] => 00 [SARAPPD_APDC_CODE] => 00 )              
Array ( [0] => 6399 [SPRIDEN_ID] => 6399 [1] => 00 [SARAPPD_APDC_CODE] => 00 )

at that point in your code does $row have your expected value?

Yes. Although is it possible the length of the array could be throwing something off? (Here is the output for print_r($row)...minus certain details :))

Array ( [0] => 6399 [SPRIDEN_ID] => 6399 [1] => A [SPRIDEN_LAST_NAME] => A [2] => A [SPRIDEN_FIRST_NAME] => A [3] => 5 [SARADAP_STYP_CODE] => 5 [4] => P [SARADAP_ADMT_CODE] => P [5] => 201102 [SARADAP_TERM_CODE_ENTRY] => 201102 [6] => 06-DEC-10 [SARADAP_APPL_DATE] => 06-DEC-10 [7] => A [SARADAP_MAJR_CODE_1] => A [8] => A [SARADAP_MAJR_CODE_CONC_1] => A [9] => 28-JAN-11 [SARADAP_APST_DATE] => 28-JAN-11 [10] => A [SARADAP_PROGRAM_1] => A [11] => A [SPRIDEN_PIDM] => A )

possibly set a variable ? $sid = $row at top of while loop and just grab that $sid for comparison later.

This doesn't appear to make a difference. I placed it at the start of the $row loop and still don't get the expected output.

The main question is what is in $dec, right before your comparison if statement.

Commenting out the if statement seems to give me exactly what I posted above for $dec. So it would seem that it isn't even getting looked at.

Again, I really appreciate the help. Hopefully my questions aren't too frustrating. I've been looking around at information on arrays and searching for similar issues but still struggling to figure this out.

In your print_r($dec)
are all of these values in the one returned val? or was this separate calls?

Array ( [0] => 4392 [SPRIDEN_ID] => 4392 [1] => 00 [SARAPPD_APDC_CODE] => 00 )
    Array ( [0] => 8471 [SPRIDEN_ID] => 8471 [1] => 00 [SARAPPD_APDC_CODE] => 00 )
    Array ( [0] => 6399 [SPRIDEN_ID] => 6399 [1] => 00 [SARAPPD_APDC_CODE] => 00 )

if there are multiple rows in the dec array like above in 1 call try this...

// comment out line 33
//$dec = oci_fetch_array($dResults);
// replace with and wrap lines 35 -42 in while loop...
while($dec = oci_fetch_array($dResults)) {
     if ($row['spriden_id'] == $dec['spriden_id']) {
        $decision = $dec['sarappd_apdc_code'];
     } else {
        $decision = "I'm not here...";
     }
}

That doesn't appear to be working either. Here is the code right now with your last suggestion.

while($row = oci_fetch_array($result))
    {
            
        $sid = $row['spriden_id'];
        var_dump($row);
        
        
         $dQuery = "select distinct 
	            spriden_id,
              sarappd_apdc_code
            from 
	             spriden,
	             saradap,
               sarappd
             where
               saradap_program_1 like '%'
              and
	             spriden_pidm = saradap_pidm
              and 
                spriden_pidm = sarappd_pidm 
              and
              	saradap_apst_code = 'C'
              and 
              	saradap_term_code_entry in ('201102')
              and
              	saradap_levl_code = '02'
             and
                sarappd_apdc_code in (select sarappd_apdc_code from sarappd
                where spriden_pidm = sarappd_pidm
                and saradap_term_code_entry = '201102'
                and sarappd_apdc_date in (select max(sarappd_apdc_date) 
                                          from sarappd
                                          where spriden_pidm = sarappd_pidm
                                          and sarappd_term_code_entry = saradap_term_code_entry
                                          and saradap_appl_no = sarappd_appl_no))
             and
              	spriden_change_ind is null";
      
                                    
        $dResults = oci_parse($conn, $dQuery);
        oci_execute($dResults);
                
        while ($dec = oci_fetch_array($dResults))
                   
        {  
         
          $did = $dec['spriden_id'];
          if ($sid== $did)
          { 
            $decision = $dec['sarappd_apdc_code'];
          }
          else
          {
            $decision = "I'm not here...";            
          }
          
          var_dump($dec);
        }
       
        
        echo "<td>".$row['SPRIDEN_LAST_NAME']."</td>";
        echo "<td>".$row['SPRIDEN_FIRST_NAME']."</td>";
        echo "<td>".$row['SPRIDEN_ID']."</td>";
        echo "<td>".$row['SARADAP_STYP_CODE']."</td>";
        echo "<td>".$row['SARADAP_ADMT_CODE']."</td>";
        echo "<td>".$row['SARADAP_TERM_CODE_ENTRY']."</td>";
        echo "<td>".$row['SARADAP_PROGRAM_1']."</td>";
        echo "<td>".$row['SARADAP_MAJR_CODE_1']."</td>";
        echo "<td>".$row['SARADAP_MAJR_CODE_CONC_1']."</td>";
        echo "<td>".$row['SARADAP_APPL_DATE']."</td>";
        echo "<td>".$row['SARADAP_APST_DATE']."</td>";
        echo "<td>".$dec['sarappd_apdc_code']."</td>";
        echo "</tr>";
        
        
                }

And this is what I'm getting for output with the var_dump. Even though I'm still not getting the decisions (in the echo) the query is still processing. So I keep going back to that if statement and don't know why it's not getting evaluated. It doesn't make sense. Syntax and logically everything looks right to me.

array(24) { [0]=> string(9) "6399" ["SPRIDEN_ID"]=> string(9) "6399" [1]=> string(6) "" ["SPRIDEN_LAST_NAME"]=> string(6) "" [2]=> string(5) "" ["SPRIDEN_FIRST_NAME"]=> string(5) "" [3]=> string(1) "5" ["SARADAP_STYP_CODE"]=> string(1) "5" [4]=> string(1) "P" ["SARADAP_ADMT_CODE"]=> string(1) "P" [5]=> string(6) "201102" ["SARADAP_TERM_CODE_ENTRY"]=> string(6) "201102" [6]=> string(9) "06-DEC-10" ["SARADAP_APPL_DATE"]=> string(9) "06-DEC-10" [7]=> string(4) "GX00" ["SARADAP_MAJR_CODE_1"]=> string(4) "GX00" [8]=> string(4) "GXED" ["SARADAP_MAJR_CODE_CONC_1"]=> string(4) "GXED" [9]=> string(9) "28-JAN-11" ["SARADAP_APST_DATE"]=> string(9) "28-JAN-11" [10]=> string(8) "GX00GXED" ["SARADAP_PROGRAM_1"]=> string(8) "GX00GXED" [11]=> string(5) "" ["SPRIDEN_PIDM"]=> string(5) "" } array(4) { [0]=> string(9) "4392" ["SPRIDEN_ID"]=> string(9) "4392" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" } array(4) { [0]=> string(9) "8471" ["SPRIDEN_ID"]=> string(9) "8471" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" } array(4) { [0]=> string(9) "6399" ["SPRIDEN_ID"]=> string(9) "6399" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" } 

 array(24) { [0]=> string(9) "8471" ["SPRIDEN_ID"]=> string(9) "8471" [1]=> string(5) "" ["SPRIDEN_LAST_NAME"]=> string(5) "" [2]=> string(7) "" ["SPRIDEN_FIRST_NAME"]=> string(7) "" [3]=> string(1) "5" ["SARADAP_STYP_CODE"]=> string(1) "5" [4]=> string(1) "P" ["SARADAP_ADMT_CODE"]=> string(1) "P" [5]=> string(6) "201102" ["SARADAP_TERM_CODE_ENTRY"]=> string(6) "201102" [6]=> string(9) "28-JUL-10" ["SARADAP_APPL_DATE"]=> string(9) "28-JUL-10" [7]=> string(4) "GX00" ["SARADAP_MAJR_CODE_1"]=> string(4) "GX00" [8]=> string(4) "GXED" ["SARADAP_MAJR_CODE_CONC_1"]=> string(4) "GXED" [9]=> string(9) "28-JUL-10" ["SARADAP_APST_DATE"]=> string(9) "28-JUL-10" [10]=> string(8) "GX00GXED" ["SARADAP_PROGRAM_1"]=> string(8) "GX00GXED" [11]=> string(6) "" ["SPRIDEN_PIDM"]=> string(6) "" } array(4) { [0]=> string(9) "4392" ["SPRIDEN_ID"]=> string(9) "4392" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" } array(4) { [0]=> string(9) "8471" ["SPRIDEN_ID"]=> string(9) "8471" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" } array(4) { [0]=> string(9) "6399" ["SPRIDEN_ID"]=> string(9) "6399" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" } 

 array(24) { [0]=> string(9) "0569" ["SPRIDEN_ID"]=> string(9) "0569" [1]=> string(5) "" ["SPRIDEN_LAST_NAME"]=> string(5) "" [2]=> string(6) "" ["SPRIDEN_FIRST_NAME"]=> string(6) "" [3]=> string(1) "5" ["SARADAP_STYP_CODE"]=> string(1) "5" [4]=> string(1) "D" ["SARADAP_ADMT_CODE"]=> string(1) "D" [5]=> string(6) "201102" ["SARADAP_TERM_CODE_ENTRY"]=> string(6) "201102" [6]=> string(9) "19-OCT-10" ["SARADAP_APPL_DATE"]=> string(9) "19-OCT-10" [7]=> string(4) "GEJ0" ["SARADAP_MAJR_CODE_1"]=> string(4) "GEJ0" [8]=> string(4) "GEJ1" ["SARADAP_MAJR_CODE_CONC_1"]=> string(4) "GEJ1" [9]=> string(9) "03-JAN-11" ["SARADAP_APST_DATE"]=> string(9) "03-JAN-11" [10]=> string(8) "GEJ0GEJ1" ["SARADAP_PROGRAM_1"]=> string(8) "GEJ0GEJ1" [11]=> string(6) "" ["SPRIDEN_PIDM"]=> string(6) "" } array(4) { [0]=> string(9) "4392" ["SPRIDEN_ID"]=> string(9) "4392" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" } array(4) { [0]=> string(9) "8471" ["SPRIDEN_ID"]=> string(9) "8471" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" } array(4) { [0]=> string(9) "6399" ["SPRIDEN_ID"]=> string(9) "6399" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" }

 array(24) { [0]=> string(9) "4392" ["SPRIDEN_ID"]=> string(9) "4392" [1]=> string(9) "" ["SPRIDEN_LAST_NAME"]=> string(9) "" [2]=> string(6) "" ["SPRIDEN_FIRST_NAME"]=> string(6) "" [3]=> string(1) "5" ["SARADAP_STYP_CODE"]=> string(1) "5" [4]=> string(1) "D" ["SARADAP_ADMT_CODE"]=> string(1) "D" [5]=> string(6) "201102" ["SARADAP_TERM_CODE_ENTRY"]=> string(6) "201102" [6]=> string(9) "28-JUL-10" ["SARADAP_APPL_DATE"]=> string(9) "28-JUL-10" [7]=> string(4) "GEE0" ["SARADAP_MAJR_CODE_1"]=> string(4) "GEE0" [8]=> NULL ["SARADAP_MAJR_CODE_CONC_1"]=> NULL [9]=> string(9) "04-AUG-10" ["SARADAP_APST_DATE"]=> string(9) "04-AUG-10" [10]=> string(4) "GEE0" ["SARADAP_PROGRAM_1"]=> string(4) "GEE0" [11]=> string(6) "" ["SPRIDEN_PIDM"]=> string(6) "" } array(4) { [0]=> string(9) "4392" ["SPRIDEN_ID"]=> string(9) "4392" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" } array(4) { [0]=> string(9) "8471" ["SPRIDEN_ID"]=> string(9) "8471" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" } array(4) { [0]=> string(9) "6399" ["SPRIDEN_ID"]=> string(9) "6399" [1]=> string(2) "00" ["SARAPPD_APDC_CODE"]=> string(2) "00" }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.