PDA

View Full Version : check against 2 sql queries?


jeepin81
05-24-2008, 10:18 PM
Hello,

I have two SQL queries in my code:

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


SQL 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'";




//################ Check for DISC#################
//################ Check for DISC #################

$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 />";

}


//################ Check for DISC #################
//################ Check for DISC#################


$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 i want it to check for DISC part no.s

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++;
}
}


Thanks everyone!
j

UPDATE: I cleaned up the code a little to make it easier to see where I'm having troubles.

bazz
05-24-2008, 10:30 PM
You might want to post (ie get this thread moved) in MySQL because I think you might be bale to do this with one query containing a sub query. Should make it more efficient and involve less php.


bazz