php - How to highlight rows if they contain duplicate data? -
i have following data:
+------+-------------------+--------------------+ | id | number | colour | +------+-------------------+--------------------+ | 1766 | 53 | red | | 1767 | 3 | green | | 1768 | 202 | green | | 1769 | 52 | blue | | 1770 | 56 | orange | | 1771 | 90 | yellow | | 1772 | 28 | teal | | 1773 | 276 | purple | | 1774 | 23 | black | | 1775 | 23 | orange | +------+-------------------+--------------------+
the important column here in colour
column. want display above rows (in html table) want highlight rows have duplicate colours. i.e. 2 green rows , 2 orange rows.
ideally end column contain boolean (or really) check when displaying table.
well, don't need subqueries or if don't have data.
just hash each row (or part of row need check) display them this:
$hashes = array(); while ($row = mysql_fetch_assoc($result)) { $rowhash = md5(implode("", $row), true); $isduplicate = isset($hashes[$rowhash])); <... printing row contents ...> $hashes[$rowhash] = true; }
this solution work until have rows display on page. may cache hash value in database.
Comments
Post a Comment