Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Dedupe a mysql output using php

Avatar of akatsuki27
akatsuki27Flag for United States of America asked on
PHP
7 Comments1 Solution377 ViewsLast Modified:
Hi,

I'm trying to figure out how to dedupe a query that I call using php that gives me duplicates. The reason being is because the ID from the main table has a one-to-many relationship with another table.

So when I

select main.column, other.column from main, other where main.ID=other.foreignkey;

I get this result:

fruit apple
fruit lemon
fruit grape
meat chicken
meat beef

I want to get rid of the duplicates in the first column. Well, not only the first because in reality I have a join where I'm using multiple tables and I don't want duplicates in those columns either.

So basically what I'm saying is I want to be able to print out 1 row per result for every column except the column from that one table.

example:

fruit     juice     red         tree      apple
                                                      lemon
                                                      grape
meat    sauce   brown   animal   chicken
                                                          beef

This is what I'm using to ouput the query:

echo "<table>";

        while($row = mysql_fetch_row($query)) {
                echo "<tr'>";
                foreach ($row as $str) {
                        echo "<td>".$str."</td>";
                }
                echo "</tr>";
        }
        echo "</table>";


I tried, and failed to do it using mysql so I'm trying now with php.  Can anybody help me out with this please? Is it clear what I'm asking for?
ASKER CERTIFIED SOLUTION
Avatar of regality
regality

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answers