0

I want to display all rows in my database into my html table but it will not repeat the same data, how can I do this? please help me thanks. here is my table.

My table:

enter image description here

Here is my html and php code:

<?php
                    $result = mysqli_query($con, "SELECT * FROM turnoveritems");

                    if (mysqli_num_rows($result) > 0) {
                    ?>
                    <table id="studentTable" class="display" border="2px">
                        <thead>
                            <tr>
                                <th>Reference #</th>
                                <th>Name</th>
                                <th>ACTION</th>
                            </tr>
                        </thead>
                        <?php
                    while ($row = mysqli_fetch_array($result)) {
                        echo "
                            <tr>
                                <td>" . $row["reference"] . "</td>
                                <td>" . $row["name"] . "</td>
                                <td class='text-center'>" . "<a href='viewturnover.php?name=" . $row['name'] . "'><i class='fa fa-eye fa-2x text-center' title='View full Details'></i></a> " ." </td>
                            </tr>";
                    } echo"</table>"; } else { echo"0 results";};
                    mysqli_close($con);
                    ?>
J.vee
  • 623
  • 1
  • 7
  • 26
renren
  • 3
  • 2

1 Answers1

1

You can Use SQL Distinct

you can query like

SELECT DISTINCT name FROM table

MORE : https://www.dofactory.com/sql/select-distinct

TarangP
  • 2,711
  • 5
  • 20
  • 41