Código PHP:
$conn=mysql_query("select * FROM TABLA1WHERE (Rem='$_FactOri') ORDER BY Parte ASC",$dbh)
or die("Problemas en el select:".mysql_error());
$conn2=mysql_query("select * FROM TABLA2 WHERE (Rem='$_FactSus') ORDER BY Num_Parte ASC",$dbh)
or die("Problemas en el select:".mysql_error());
echo "<table border=0 width='700px'>";
echo "<tr>";
echo "<td colspan='2' style='color:#A9A9A9;'>Factura: <strong>".$_FactOri."</strong></td>";
echo "<td colspan='3' style='color:#A9A9A9;'>Factura: <strong>".$_FactSus."</strong></td>";
echo "<tr>
<td><strong># de Parte Original</strong></td>
<td><strong>Cantidad Original</strong></td>
<td><strong># de Parte Sustitución</strong></td>
<td><strong>Cantidad Sustitución</strong></td>
<td><strong>Diferencias</strong></td>
</tr>";
while (($row=mysql_fetch_array($conn))&&($rowB=mysql_fetch_array($conn2))){
$_varA = $row['Parte'];
$_varB = $row['Cantidad'];
$_varC = $rowB['Num_Parte'];
$_varD = $rowB['Cantidad'];
if ($_varA == $_varC) {
$resultado = $_varB - $_varD;
echo "<tr>";
echo "<td>".$_varA."</td>";
echo "<td align='center'>".$_varB."</td>";
echo "<td>".$_varC."</td>";
echo "<td align='center'>".$_varD."</td>";
echo "<td>".$resultado."</td>";
echo "</tr>";
} else{
echo "<tr>";
echo "<td>".$_varA."</td>";
echo "<td align='center'>".$_varB."</td>";
echo "<td>".$_varC."</td>";
echo "<td align='center'>".$_varD."</td>";
echo "<td>".$resultado."</td>";
echo "</tr>";
}
}