Results 1 to 2 of 2

Thread: Issue in duplicate display data

  1. #1
    Join Date
    Sep 2010
    Posts
    188

    Issue in duplicate display data

    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:

    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;'>&nbsp;$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;'>&nbsp;</td>
            <td style='border: none;'>&nbsp;$row_sub[SubItems]</td>
            <td style='border: none;'>&nbsp;$row_sub[ItemCode]</td>
            <td>&nbsp;</td>
            <td style='border: none;' size='3'>&nbsp;$row_sub[UoM]</td>
            <td style='border: none;'>&nbsp;$row_sub[Class]</td>
            <td style='border: none;'>&nbsp;$row_sub[Description]</td>
            <td style='border: none;'>&nbsp;$row_sub[BINLocation]</td>     
            </tr>";
    
    }
    }    
    ?>
    I will attach my sample page.

    Thank you
    Attached Images Attached Images

  2. #2
    Join Date
    Mar 2012
    Posts
    93

    Issue in duplicate display data

    If your data is display duplicate data then you may used group by... it is used to avoid duplicate data...

Similar Threads

  1. Need help getting data to display on button click
    By brickout in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 03 Aug 2010, 05:11 PM
  2. Display .mdb data help :)
    By quinnwizard in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 14 Nov 2009, 04:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •