Jump to content

Issue in duplicate display data


newphpcoder

Recommended Posts

Hi...

 

I encountered problem in my query and while loop my data was duplicates when I join 2 tables, because the one field that I need to display is from another table.

 

here is my code:

 

<div>
<table>
<thead>
<th>Items</th>
<th>Sub Items</th>
<th>Item Code</th>
<th>Demanded Qty</th>
<th>UoM</th>
<th>Class</th>
<th>Description</th>
<th>BIN Location</th>
</thead>
<?php
$sql = "SELECT Items FROM bom_items ORDER BY Items";
$res_bom = mysql_query($sql, $con);

while($row = mysql_fetch_assoc($res_bom)){
echo "<tr>
        <td style='border: none;font-weight: bold;'> $row[items]</td>
        </tr>";       
//$sql = "SELECT SubItems, ItemCode, UoM, Class, Description FROM bom_subitems WHERE Items = '$row[items]' ORDER BY Items"or die(mysql_error());
//$sql = "SELECT DISTINCT bs.SubItems, bs.ItemCode, bs.UoM, bs.Class, bs.Description,w.BINLocation FROM bom_subitems bs LEFT JOIN wms w ON bs.Items = w.Items WHERE bs.Items = '$row[items]' AND w.Items = '$row[items]' ORDER BY bs.Items, w.Items"or die(mysql_error());
$sql = "SELECT DISTINCT bs.SubItems, bs.ItemCode, bs.UoM, bs.Class, bs.Description,w.BINLocation FROM bom_subitems bs, wms w WHERE bs.Items = '$row[items]' AND w.Items = '$row[items]' ORDER BY bs.Items, w.Items"or die(mysql_error());
$res_sub = mysql_query($sql, $con);

while($row_sub = mysql_fetch_assoc($res_sub)){
    echo "<tr>
        <td style='border: none;'> </td>
        <td style='border: none;'> $row_sub[subItems]</td>
        <td style='border: none;'> $row_sub[itemCode]</td>
        <td> </td>
        <td style='border: none;' size='3'> $row_sub[uoM]</td>
        <td style='border: none;'> $row_sub[Class]</td>
        <td style='border: none;'> $row_sub[Description]</td>
        <td style='border: none;'> $row_sub[bINLocation]</td>     
        </tr>";

}
}    
?>

 

I will attach my sample page.

 

Thank you

post-101569-1348240335134_thumb.jpg

Link to comment
Share on other sites

you need to most likely use count distinct. 8)

 

SELECT COUNT (DISTINCT , bs.SubItems, bs.ItemCode, bs.UoM, bs.Class, bs.Description,w.BINLocation) FROM bom_subitems bs, wms w WHERE bs.Items = '$row[items]' AND w.Items = '$row[items]' ORDER BY bs.Items, w.Items

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.