Jump to content

Loop Problem


jeepin81

Recommended Posts

Hello,

 

I have two queries in my code:

 

Query-1.) joins 3 tables together to get the correct information form the user input and displays the infor

 

 

Query-2.) Takes the same user input and check a different table to see if that Part number is "DISC".

 

If it is "DISC" I want to check that against my first queries in the while loop and have it say - please contact......

 

They both work fine and I can get it to echo "please contact..." for the last part # that is "DISC" but it wont echo "please contact..." for the preceding "DISC" part #'s???

 

I'm having some kind of loop issue and I am not sure where to go from here. Any help would be greatly appreciated.

 

$sqlStatment = "SELECT rdmitm, rmdesc, rditem, rdqty, psdesc, pitem 
                FROM files.retimst, files.retidtl LEFT JOIN files.itempict 
                ON rditem = pitem 
                WHERE rmitem = rdmitm AND rdmitm = '$uppercase'"; 
     
     
     
     
//################ Query 2 ################# 
//################ Query 2 ################# 
                 
$sqlStatment2 = "SELECT rditem, iitem, ico, imfgno, rdmitm 
                 FROM files.retidtl, files.itemmast 
                 WHERE iitem = rditem AND ico = '1' AND imfgno LIKE '%DISC%' and rdmitm = '$uppercase'"; 

$stmt2 = db2_prepare($i5db2, $sqlStatment2) 
                    or die ("Prepare error 2: " . db2_stmt_errormsg()); 

$result2 = db2_execute($stmt2) 
                    or die ("Execute error 2: " . db2_stmt_errormsg()); 
                     
while ($row2 = db2_fetch_assoc($stmt2)){ 

//this part works fine and is for testing 
echo " This is the DISC PART NUMBER "; 
$DISC = $row2['IITEM']; 
echo $DISC; 
echo "<br />"; 

    }                         
                                 
                                                                      
//################ Query 2 ################# 
//################ Query 2 #################                 
                 
                 
$stmt = db2_prepare($i5db2, $sqlStatment) 
                    or die("Prepare error: " . db2_stmt_errormsg()); 
                     
$result = db2_execute($stmt) 
          or die("Execute error: " . db2_stmt_errormsg()); 
           
while ($row = db2_fetch_assoc($stmt)) 
{ 

$row_color = ($row_count % 2) ? $color1 : $color2; 

   
  echo "<tr>"; 
  echo "<td bgcolor=\"$row_color\">"; 
  echo "<span class=\"fonta\">"; 

// this is where is only matches against the last DISC part no. 

if($row['RDITEM'] == $DISC){ 
  echo ucfirst($row['RDITEM']); 
  echo "<br />"; 
  echo " Contact Customer Service for This Part #"; 
  } 
  else { 
  echo ucfirst($row['RDITEM']); 
  echo "<br />"; 
  } 


  echo"</span>"; 
  echo "<span class=\"fontc\">"; 
  echo ucfirst($row['PSDESC']); 
  echo "</span>"; 
  echo "</td>"; 
  echo "<td width=\"65\" bgcolor=\"$row_color\"><div align=\"center\">"; 
  echo "<span class=\"fonta\">"; 
  echo ucfirst($row['RDQTY']); 
  echo "</span>"; 
  echo "</div></td>"; 
  echo "</tr>"; 
   
  $row_count++; 
} 
} 

 

 

Any insight would be appriecated.

 

Thanks Everyone!

j

Link to comment
https://forums.phpfreaks.com/topic/106927-loop-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.