Click to See Complete Forum and Search --> : displaying search results in a non repeating way


Jim_Madrid
03-11-2003, 06:50 AM
PHP & MYSQL

I have a taxonomic database of animal species (phylum, class, order, family, species, etc) and would like to know if there is a way to display search results without repeating each category for each species. In other words, I want to avoid example 1 and achieve example 2. That is, if the name of the species changes but the prior categories stay the same I donīt want to repeat every category.

Example 1 NO!

Class Order Family Species 1
Class Order Family Species 2
Class Order Family Species 3
Class Order 2 Family 2 Species 4
Class Order 2 Family 2 Species 5
Class Order 2 Family 2 Species 6
Class Order 2 Family 3 Species 7
Class Order 2 Family 3 Species 8

Example 2 YES!

Class Order Family Species 1
Species 2
Species 3
Order 2 Family 2 Species 4
Species 5
Species 6
Family 3 Species 7
Species 8


Any ideas would be greatly appreciated.

James

Pig
03-13-2003, 06:52 PM
$result = mysql_query("SELECT * FROM table_name")
while( $row = mysql_fetch_array($result) )
{
$row0 = $row[0];
$row1 = $row[1]
$row2 = $row[2]
$row3 = $row[3]

if( $row0 == $row0set )
{
unset($row0);
}
if( $row1 == $row1set )
{
unset($row1);
}
if( $row2 == $row2set )
{
unset($row2);
}

echo("
$row0, $row1, $row2, $row3
");
$row0set = $row0;
$row1set = $row1;
$row2set = $row2;
}


Someone try that and see if it works. I'm at work and cant do it from here.

The idea is that if a new items comes along, it'll be printed, other wise it gets blanked. That is, a new value for $rowX will keep it from being unset, and every identical one after that will match, and there fore get unset.

Lemme know if that worked.