Page 1 of 1

help... please!

Posted: Sun Oct 27, 2002 1:51 pm
by DynamiteHost
Hey,

I have this code:

Code: Select all

$query = mysql_query("SELECT * FROM products WHERE product ='$id'") or die ("Unable to get product list from the database.");

while ($view = mysql_fetch_array($query)) {

print $product;

}

The thing is I want to know how to ignore duplicate entries when printing out the products....

i have a field called $name where there will be duplicate entries...

please help :)

DISTINCT

Posted: Sun Oct 27, 2002 3:33 pm
by phpScott
try this

Code: Select all

$query = mysql_query("SELECT DISTINCT FROM products WHERE product ='$id'") or die ("Unable to get product list from the database."); 

while ($view = mysql_fetch_array($query)) { 

print $product; 

}
Here is the link for more info about SELECT statements
http://www.mysql.com/doc/en/SELECT.html

phpScott

Posted: Sun Oct 27, 2002 3:50 pm
by DynamiteHost
Would that work?

Because the rows aren't complete duplicates... it's just the one field in a row might be the same as in another....

sorry

Posted: Sun Oct 27, 2002 4:41 pm
by phpScott
:( Where I use the Distinct clause is a little bit different then your application of it. I tried several dif ways of trying to get the results you are looking for from a quick sample db and I couldn't, I am wondering if they might be a better way to structure your table or tables to get the desired results.
Any one esle with some bright :idea:

phpScott

Posted: Mon Oct 28, 2002 3:55 am
by Wayne
which column is it you would be removing duplicate entries?? if the column was say ProductName then try

Code: Select all

SELECT DISTINCT(ProductName),* ...