Author Topic: Why this SELECT DISTINCT function doesn't work ?  (Read 580 times)

0 Members and 1 Guest are viewing this topic.

Offline vanvoquanTopic starter

  • Irregular
  • Posts: 40
    • View Profile
Why this SELECT DISTINCT function doesn't work ?
« on: June 19, 2008, 03:26:03 AM »
I try to eliminate the duplicate values with Select Distinct but is doesn't work. Can anybody tell me why is not working. Any suggestion will be greatly appricitate. Here is the
Code: [Select]
[<td><?php
$datas
=$_GET['keywords'];
$result=mysql_db_query($dbname,"SELECT products_id FROM products_description WHERE products_name LIKE'%$datas%'");
while(
$category1 mysql_fetch_array($result))
{
$result2=mysql_db_query($dbname,"SELECT categories_id FROM products_to_categories WHERE products_id='"$category1['products_id'] ."'");
while(
$category2 mysql_fetch_array($result2))
{
$result3=mysql_db_query($dbname,"SELECT parent_id FROM categories WHERE categories_id='"$category2['categories_id'] ."'");
while(
$category3 mysql_fetch_array($result3))
{
$result5=mysql_db_query($dbname,"SELECT parent_id FROM categories WHERE categories_id='"$category3['parent_id'] ."'");
while(
$category4 mysql_fetch_array($result5))
{
$result6=mysql_db_query($dbname,"SELECT parent_id FROM categories WHERE categories_id='"$category4['parent_id'] ."'");
while(
$category5 mysql_fetch_array($result6))
{
$result7=mysql_db_query($dbname,"SELECT DISTINCT categories_description.categories_name, categories.categories_id, categories.parent_id FROM categories_description, categories WHERE  categories_description.categories_id = categories.categories_id AND categories.categories_id ='"$category5['parent_id'] ."'");
while(
$row mysql_fetch_array($result7))
  {
  echo 
$row['categories_name'];
echo 
"<br>";
}
}
}
}
}
}
?>
</td>/code]

Offline vanvoquanTopic starter

  • Irregular
  • Posts: 40
    • View Profile
Re: Why this SELECT DISTINCT function doesn't work ?
« Reply #1 on: June 19, 2008, 12:43:25 PM »
Can anyone please help me with this. Millions thanks
Vanvoquan

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,443
  • Gender: Male
    • View Profile
Re: Why this SELECT DISTINCT function doesn't work ?
« Reply #2 on: June 19, 2008, 01:55:19 PM »
DISTINCT is not a function -- it will only removes duplicates across the entire column list, not just the first field.
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.