I’ve quote a simple database collecting simple information. There is a high chance of creating identical entries.
$sql = "INSERT INTO track_table (sitename, affiliate, refferal) values ('$sitename', '$affiliate', '$refferal')";
on a separate page, I pull a report
$result = $mysqli->query("SELECT sitename, affiliate, refferal FROM track_table")
or die("Problem executing query.");
print "<table border=1>\n";
print "<tr><td><b>SITENAME</b></td><td><b>AFFILIATE</b></td><td><b>REFFERAL</b></td></tr>";
while ($row = $result->fetch_array()) {
echo "<td>", $row['sitename'], "</td><td>", $row['affiliate'], "</td><td>", $row['refferal'], "</td></tr>\n";
}
echo "</table>\n";
This outputs
SITENAME ------------ AFFILIATE ------------- REFFERAL
foo.com ---------------12345------------------bar.com
foo.com ---------------12345------------------bar.com
abc.com ---------------98765------------------xyz.com
as you can see, I can have 2 identical entries. Is there a way I can calculate 1 and 2 being the exact same, so not showing them, but perhaps in a new col that shows (2)
SITENAME ------------ AFFILIATE ------------- REFFERAL-------COUNT
foo.com ---------------12345------------------bar.com---------(2)
abc.com ---------------98765------------------xyz.com---------(1)
Use GROUP BY:
If you don’t need the count column then you could use
SELECT DISTINCTinstead: