Hi,

I have a table

id - Product_Name - Price - image

Some value like :

1 - My Product A - 50 - mpa.jpg
2 - My Product B - 10 - mpb.jpg
3 - My Product A - 40 - mpc.jpg
4 - My Product C - 20 - mpd.jpg

i need product image of unique product based on minimum value. i am useing this query

SELECT id, Product_Name, MIN(Price), image FROM table GROUP BY Product_Name

It is showing right min price but the it is wrong, that's why i am geting image wrong, please help me to fix this

Honestly, your query looks good to me. Unless, you made a mistake in referring to the image.

<img src="directory/<?php echo $row['image'];?>" />

should give you something like this

<img src="directory/mpb.jpg" />

remember you query looks for the minimum price for each Product_name and not the MIN of all prices. Still, this scenario will not create an image mismatched.

in case of same name product id and image giveing wrong

thanks for you reply i have solve this issue with sub query. thakns again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.