help... please!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
DynamiteHost
Forum Commoner
Posts: 69
Joined: Sat Aug 10, 2002 5:33 pm

help... please!

Post 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 :)
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

DISTINCT

Post 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
DynamiteHost
Forum Commoner
Posts: 69
Joined: Sat Aug 10, 2002 5:33 pm

Post 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....
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

sorry

Post 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
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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),* ...
Post Reply