Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

php - Is there a function to hide duplicates in one column although the other columns contain different values?

I created a table with information from several tables. The result of the table looks like this:

enter image description here

and I want like this:

enter image description here

The article number occurs several times. I would like only one article number. It doesn't matter which row is hidden. It is important that only one article. The sorting should then still be according to erranf_zeit in ascending order.

My PHP code and query in MS SQL looks like this:

    if( $conn ) 
    {
        # echo "Connection established.<br />";
    }
    else
    {
        echo "Es konnte leider keine Verbindung aufgebaut werden.<br />";
        die( print_r( sqlsrv_errors(), true));
    }
    
    $query ="SELECT TOP 30 m.artikel,b.order, z.plan_auftrag, m.bez_1, m.bez_2, m.artikel_bez, b.masch_nr, b.erranf_zeit,b.erranf_dat, s.a_status";
    $query.=" FROM [hydra1].[hydadm].[v_auftrags_zusatz] z";
    $query.=" JOIN [hydra1].[hydadm].[auftrags_bestand] b";
    $query.=" ON z.auftrag_nr = b.aunr";
    $query.=" JOIN [hydra1].[hydadm].[v_auftrag_status] s";
    $query.=" ON b.auftrag_nr = s.auftrag_nr";
    $query.=" JOIN [hydra1].[hydadm].[mlst_hy] m";
    $query.=" ON s.auftrag_nr = m.auftrag_nr";  
    $query.=" AND s.a_status IN ('V','L')";
    $query.=" AND m.kennz = 'M'";
    $query.=" AND s.eingeplant = ('M')";
    
    if (isset($_GET['maschine']) AND $_GET['maschine'] > '0')
    {   
        $query.=" AND b.masch_nr='$_GET[maschine]'";    
    }
    $query.=" ORDER BY s.a_status ASC, b.erranf_dat ASC, b.erranf_zeit ASC";
    
    
    //SELECT COUNT(*), m.artikel
    //FROM [hydra1].[hydadm].[mlst_hy] m
    //GROUP BY m.artikel
    //HAVING COUNT(*) > 1
    
    $result = sqlsrv_query($conn, $query);
    
  
    $i='';

    $trenner = '';

    while($row=sqlsrv_fetch_array($result))
    {
            
        if ($row['artikel'] != $trenner)
            
        {

        echo "<tr class=grey>";
        
            echo "<td>$row[artikel]</td>";

            echo "<td>";
            echo $row['plan_auftrag'];          
            echo "</td>";

            echo "<td>";
            echo $row['bez_1'];
            echo "</td>";
         
            echo "<td>";
            echo $row['bez_2'];
            echo "</td>";

            echo "<td>";
            echo $row['artikel_bez'];
            echo "</td>";

            echo "<td>";
            echo $row['masch_nr'];
            echo "</td>";
            
            echo "<td>";
    echo substr($row['erranf_dat']->format('d.m.Y H:i:s:u'), 0, -16);
    echo " - ";
            echo gmdate("H:i", $row['erranf_zeit']);
            echo "</td>";

            echo "<td>";
            
                if ($row['a_status']=="E")
                {
                echo "beendet";
                }
                else if ($row['a_status']=="L")
                {
                echo "laufend";
                }
                else if ($row['a_status']=="V")
                {
                echo "vorbereitet";
                }
                else if ($row['a_status']=="U")
                {
                echo "unterbrochen";
                }
            
            echo "</td>";
            
            echo "</tr>";       
            
        }

    $trenner = $row['artikel'];         

    }

}
question from:https://stackoverflow.com/questions/66053572/is-there-a-function-to-hide-duplicates-in-one-column-although-the-other-columns

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...