Hi,

I am returning rows from a SQL query with a

do {
 echo $row_rsAnimals['animals'];
} while ($row_rsAnimals = mysql_fetch_assoc($rsAnimals));

this loop can then echo out each returned row and display the results.

What i want to do is to be able to echo out only unique values from the animal field

I figured i would need to combine each result into an array and then use array_unique to remove duplicates.

If someone could show me how to create the array in the loop to get me started, that would appreciated, still not got my head around arrays

Cheers

    Thanks Brad... the field contains a comma delimited string of more than 1 animal so cannot use SQL to return unique animals

      Dereksdontrun wrote:

      the field contains a comma delimited string of more than 1 animal so cannot use SQL to return unique animals

      The field should not contain a comma delimited string in the first place. You should avoid such multi-valued fields, e.g, by introducing another table. Read this article on Database Normalization and Design Techniques.

        I agree with above that you should really avoid such database design practices; however, if you're unable to change it you can use the explode function to put the comma-separated list into an array then use the array_unique() function to remove the duplicates and you're left with the unique animals.

          Thanks for all your input...i have taken on board all the advice given and will change my database accordingly

          cheers

            Write a Reply...