Compare Two tables and show records with same value
Posted: Thu Feb 26, 2009 6:42 am
Hello Friends.
I am new to PHP. I am doing a project in which there are two tables :1.Order_Detail table 2.Inventory table.I want to compare two tables and show records that are same in both tables in color and remaining in normal way. i.e., If order_detail table contains 4 records and inventory contains 2 records which is same in order_detail table, then first two records should be shown wit some color and next two in normal way. I did almost all the code but it shows all four records in some color.
Please any one help me i worked a lot but it is all in vain..

the Code is here::
I am new to PHP. I am doing a project in which there are two tables :1.Order_Detail table 2.Inventory table.I want to compare two tables and show records that are same in both tables in color and remaining in normal way. i.e., If order_detail table contains 4 records and inventory contains 2 records which is same in order_detail table, then first two records should be shown wit some color and next two in normal way. I did almost all the code but it shows all four records in some color.
Please any one help me i worked a lot but it is all in vain..
the Code is here::
Code: Select all
<table width="750" height="28" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#C6C6C6">
<tr>
<?php
$line1="";
$result = mysql_query("SELECT ORDER_DETAIL.SL_NO AS SL_NO,ORDER_DETAIL.BUN_NO AS BUN_NO, ORDER_DETAIL.DENSITY AS DENSITY, ORDER_DETAIL.GRADE AS GRADE, SIZE.LENGTH AS LENGTH,ORDER_DETAIL.SI_ID AS SI_ID,ORDER_DETAIL.TH_ID AS TH_ID,SIZE.WIDTH AS WIDTH, ORDER_DETAIL.COLOR AS COLOR, THICK.THICK AS THICK,THICK.NO_OF_SHEETS AS NO_OF_SHEETS FROM THICK, ORDER_DETAIL,SIZE,ORDER_NO WHERE ORDER_NO.OR_ID ='".$_REQUEST["id"]."' AND ORDER_NO.ORDER_COMP ='0' AND ORDER_DETAIL.TH_ID = THICK.TH_ID AND ORDER_DETAIL.SI_ID = SIZE.SI_ID AND ORDER_NO.OR_ID = ORDER_DETAIL.OR_ID ORDER BY ORDER_DETAIL.SL_NO ASC");
while ($line = mysql_fetch_array($result)) {
$result1=mysql_query("SELECT * FROM INVENTORY WHERE DENSITY = '".$line["DENSITY"]."'AND SI_ID = '".$line["SI_ID"]."' AND TH_ID = '".$line["TH_ID"]."' AND GRADE = '".$line["GRADE"]."' AND COLOR = '".$line["COLOR"]."'");
$line1=$line1-1;
$r1=mysql_fetch_array($result1);
$line1=mysql_num_rows($result1);
if($line1)
{
?>
<td ><div align="center">
<input name="sl_no" id="sl_no" type="hidden" value="<?php echo $line["SL_NO"] ?>" >
</div></td>
<td ><div id="newval_<?php echo $line["SL_NO"] ?>">
<input id='bun_no' name='bun_no' readonly='1' type="text" value="<?php echo $line["BUN_NO"] ?>" size="5" >
</div></td>
<td width="75" bgcolor="#FF80FF"><div align="center">
<input name="density" bgcolor="#FF80FF" type="text" value="<?php echo $line["DENSITY"]?>" size="5">
</div></td>
<td width="75"><div align="center">
<input name="grade" bgcolor="#FF80FF"value="<?php echo $line["GRADE"]?>" type="text" size="5">
</div></td>
<td width="75"><div align="center">
<input name="si_len" bgcolor="#FF80FF" type="text" value="<?php echo $line["LENGTH"]?>x<?php echo $line["WIDTH"]?>" size="5">
</div></td>
<td width="75"><div align="center">
<input name="color" bgcolor="#FF80FF" type="text" value="<?php echo $line["COLOR"]?>" size="5">
</div></td>
<td width="75"><div align="center">
<input name="thick" bgcolor="#FF80FF" type="text" value="<?php echo $line["THICK"]?>" size="5">
</div></td>
<td width="75"><div align="center">
<input name="no_of_sheets" bgcolor="#FF80FF" type="text" value="<?php echo $line["NO_OF_SHEETS"]?>" size="5">
</div></td>
<td width="75"><div align="center">
<?php echo (float) $line["THICK"]*(float) $line["NO_OF_SHEETS"]?>mm</div></td>
<?php
$a = 598 ;
$b = 72 ;
$c = 36 ;
(float) $weight = ((((($line["DENSITY"]/598)*($line["THICK"]*$line["NO_OF_SHEETS"]))/72)*$line["LENGTH"])/36)*$line["WIDTH"]
?>
<td width="75"><div align="center">
<input name="weight" type="text" value="<?php echo $weight?>" size="5">
</div></td>
<td width="75"><div align="center"><input name="bun_id" type="checkbox" value="<?php echo $line["SL_NO"] ?>"></div></td>
</tr>
<?php
}
else
{
?>
<td ><div align="center">
<input name="sl_no" id="sl_no" type="hidden" value="<?php echo $line["SL_NO"] ?>" >
</div></td>
<td ><div id="newval_<?php echo $line["SL_NO"] ?>">
<input id='bun_no' name='bun_no' readonly='1' type="text" value="<?php echo $line["BUN_NO"] ?>" size="5" >
</div></td>
<td width="75" bgcolor="#FF80FF"><div align="center">
<input name="density" type="text" value="<?php echo $line["DENSITY"]?>" size="5">
</div></td>
<td width="75"><div align="center">
<input name="grade" value="<?php echo $line["GRADE"]?>" type="text" size="5">
</div></td>
<td width="75"><div align="center">
<input name="si_len" type="text" value="<?php echo $line["LENGTH"]?>x<?php echo $line["WIDTH"]?>" size="5">
</div></td>
<td width="75"><div align="center">
<input name="color" type="text" value="<?php echo $line["COLOR"]?>" size="5">
</div></td>
<td width="75"><div align="center">
<input name="thick" type="text" value="<?php echo $line["THICK"]?>" size="5">
</div></td>
<td width="75"><div align="center">
<input name="no_of_sheets" type="text" value="<?php echo $line["NO_OF_SHEETS"]?>" size="5">
</div></td>
<td width="75"><div align="center">
<?php echo (float) $line["THICK"]*(float) $line["NO_OF_SHEETS"]?>mm</div></td>
<?php
$a = 598 ;
$b = 72 ;
$c = 36 ;
(float) $weight = ((((($line["DENSITY"]/598)*($line["THICK"]*$line["NO_OF_SHEETS"]))/72)*$line["LENGTH"])/36)*$line["WIDTH"]
?>
<td width="75"><div align="center">
<input name="weight" type="text" value="<?php echo $weight?>" size="5">
</div></td>
<td width="75"><div align="center"><input name="bun_id" type="checkbox" value="<?php echo $line["SL_NO"] ?>"></div></td>
</tr>
<?php
}
}
?>
</table>