CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Removing duplicates from a two table list (http://www.codingforums.com/showthread.php?t=285209)

rgEffects 01-03-2013 05:01 PM

Removing duplicates from a two table list
 
I have some code that creates a very nice indented list like this:
  • first item
  • second item
    • Child of Second Item
  • third item

Table A has a column for id, childID and name. The code works just fine for a single table but if I want to add another table and remove the duplicates using WHEN tableB.tableAChildID = tableA.childID I get no results. Here's the code that is not working:
PHP Code:

<?php
    $parentid 
0// assuming that 0 is the main category.
    
get_sub_cats($parentid);
    function 
get_sub_cats($parentid) {
    
    
$sql "SELECT
    tableA.id, tableA.childID, tableA.name,
    tableB.tableAchildID
    FROM tableA, tableB
    WHERE tableA.childID = "
.$parentid."
        AND tableA.childID = tableB.tableAChildID
    "

    
$countID $rec['tableA.id'];
    
$run mysql_query($sql);
    
$newLink "'bizCatEdit.php?recordID=" ;
    
$hypnen "'";
    echo 
'<ul class="aqtree3clickable">';
        while (
$rec mysql_fetch_assoc($run)) {
        echo 
'<li />SN:'$rec['id'], ' - ',  $rec['bcName'], ' / '$rec['BBS']; 
        
get_sub_cats($countID);
        }
    echo 
'</ul>';
    }
    
?>

If I remove the AND method I end up with a table that looks like this:
  • first item
  • first item
  • first item
  • second item
  • second item
  • second item
  • Child of Second Item
  • Child of Second Item
  • Child of Second Item
  • third item
  • third item
  • third item
Removing
PHP Code:

 $countID $rec['tableA.id']; 

and changing the line
PHP Code:

 get_sub_cats($countID); 

to
PHP Code:

 get_sub_cats($rec['id']); 

Brings back the indents like this:
  • first item
  • first item
  • first item
  • second item
    • Child of Second Item
  • second item
    • Child of Second Item
  • second item
    • Child of Second Item
  • third item
  • third item
  • third item
Any ideas how I can remove the duplicates?


All times are GMT +1. The time now is 08:59 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.