I have 2 tables in a SQL database and I want to compare columns from them, then when there are more than 1 duplicate entries I want to count them and display with PHP and create a list of only the pageCatagorys that are duplicates
My two Tables look like this:
Table: pageCatagorys
ID | catagory
1 | Home
2 | Test 1
3 | Other Services
Table: pages
ID | pageName | pageCatagory | pageURL
1 | Test 1 | Test 1 | test-1
2 | Test 2 | Test 1 | test-2
3 | Test 3 | Home | test-3
4 | Test 4 | Other Services | test-4
When I run the query $pagecount = mysql_query("SELECT pageCatagory, COUNT(*) FROM pages GROUP BY pageCatagory HAVING COUNT(*) > 1");
in phpMyAdmin i get the below result table:
pageCatagory | COUNT(*)
Test 1 | 2
However its always hitting the else rule in my code below.
<?php
$sql = mysql_query("SELECT catagory FROM pageCatagorys");
while($row = mysql_fetch_assoc($sql)) {
$pagecount = mysql_query("SELECT pageCatagory, COUNT(*) FROM pages GROUP BY pageCatagory HAVING COUNT(*) > 1");
if($pagecount > 1){
?>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><?php echo $row["catagory"] ?><span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<?php $sql1 = mysql_query("SELECT pageName, pageURL FROM pageURL");
while($row1 = mysql_fetch_assoc($sql1)) { ?>
<li><a href="<?php echo $row["pageName"] ?>"><?php echo $row["pageName"] ?></a></li>
<li class="divider"></li>
<?php } ?>
</ul>
<?php } else { ?>
<li><a href="#"><?php echo $row["catagory"] ?></a></li>
<?php } } ?>