I don't see an easy way to do this in one SQL statement. But, the
following PHP does the trick for me (assuming MySQL):

// get the list of Y values
$r = mysql_query( "SELECT * FROM table GROUP BY Y" );
while( $y_val = mysql_fetch_array( $r ) )
        $y_vals[] = $y_val['Y'];

// For each Y, fetch the Xs from the table
foreach( $y_vals as $y )
{
        echo "<hr>$y<br>";
        // get all the Xs for this Y
        $r = mysql_query( "SELECT * FROM table WHERE Y='$y'" );
        while( $row = mysql_fetch_array( $r ) )
                echo $row['X'] . "<br>";
}

Let us know if this works.

--Dave

On Mon, 2002-12-02 at 00:53, Victor wrote:

> Consider the following table:
> 
> U | X | Y 
> --|---|--
> me|001|0a
> me|002|0a
> me|003|0a
> me|002|0b
> me|003|0b
> me|004|0b
> ..|...|..
> 
> then the code says:
> 
> SELECT * FROM Y WHERE U = me
> 
> So now what?
> - remember I do not know the value of Y, so it has to be an automatic
> thing; I can't just say ... WHERE U = me AND Y = a.
> 
> I want this output:
> 
> 0a
> 001
> 002
> 003
> _______________________ (<hr>)
> 
> 0b
> 002
> 003
> 004 
> 
> How the hell do I do that? I can't think of the goddamn' syntax!
> 
> ______________________________________________________________________ 
> 
> Post your free ad now! http://personals.yahoo.ca
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to