Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-03-2013, 05:01 PM   PM User | #1
rgEffects
New Coder

 
Join Date: Aug 2012
Posts: 76
Thanks: 22
Thanked 0 Times in 0 Posts
rgEffects is an unknown quantity at this point
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?
rgEffects is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:12 PM.


Advertisement
Log in to turn off these ads.