I have a simple query to pull all the data from a table but I only need display the value once no matter how many times its in the table. Right now I get the following results:

Material in Que
9231500
9231500
9231500
Grp1298
Grp1298
6251752
6251752 

What my desired result is to get:

Material in Que
9231500
6251752
Grp1298

How Do I sort out repeating numbers or Text from my query results? For the array with column 3 from my table $row[2]

<?php session_start(); ?>  
<html>
    <head>
        <basefont face="Arial">
        <title>Material in Testing que</title>
    </head>

    <body>
    <?php

    // set database server access variables:
    include('db.php');

    // open connection
    $connection = mysqli_connect($host, $user, $pass, $db); 
    if (mysqli_connect_errno($connection)) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    // create query
    $query = "SELECT * FROM testingqa1160";
    $result = mysqli_query($connection, $query);

    if (mysqli_num_rows($result) > 0) {
        echo "Material in Testing Que";
        echo "<br>";

        while($row = mysqli_fetch_row($result)) {
            echo $row[2];
            echo "<br>";
            echo "  ";
        }
    }
    else {
        // print status message
        echo "<center>";
        echo " Que Empty </font>";
        echo "</center>";
    }

    mysqli_free_result($result);

    // close connection
    mysqli_close($connection);

    ?>
    </body>
</html>
有帮助吗?

解决方案 2

you can us group by clause

$query = "SELECT * FROM testingqa1160 GROUP BY colname";
                $result = mysqli_query($connection, $query);

其他提示

Use MySQL's DISTINCT in your query:

$query = "SELECT DISTINCT colname FROM testingqa1160";
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top