Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Omitting duplicate results from query


henry0 - 8:42 pm on Jul 19, 2008 (gmt 0)


It looks like WHERE EXISTS has somme limitation for example:
If a row exists and contains nothing but NULL value
then it will be still returned
MANUAL [dev.mysql.com]

Instead you could use a nested query such as:
select category_name
from etc..
do a first num rows $num=....
// first while
$i=0;
while ($i<$num)
{
$cat_name=.....
echo the cat name rows

// note we do not close the first curly bracket
// second query

select etc...
do a second num rows
but name $result $result 2 $num $num2 and $i $i2
(to avoid query confusion)
$i2=0;
while ($i2<$num2)
{
grab and echo the rest of your fields

++$i2;
}// ends $i2 while

++$i;
} // ends $i while

it's up to you to adding the sub query conditions (Where....)

the above will display each category with its related products one section at a time.

<edit>Typo</edit>

[edited by: henry0 at 9:04 pm (utc) on July 19, 2008]


Thread source:: http://www.webmasterworld.com/php/3702468.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com