I am trying to get a heading for compatibility once with a list of products that are compatible below it. Below is the PHP code for the bit where I want the compatibility shown once.
The table includes info like:
Product; Compatible
iphone 4 car charger ; iphone 4
iphone 4 mains charger; iphone 4
iphone 4 usb cable; iphone 4
My problem is my php provides me with a list that says “iphone 4” 3 times in the case above.
How can I make it so that when there are multiple entries with the same value it just uses it once? I did think may be I could remove the .$row bits of code but before I tried that I wanted to get an expert view.
placing the column that comes after the word DISTINCT in parentheses does ~not~ restrict the distinctness to that column
DISTINCT applies to ~all~ columns in the SELECT clause, and ensures that there are no duplicate rows (i.e. combination of all columns)
if you have multiple compatible values in the results and want only one, you have to have some rule for deciding which name to show along with each compatible – lowest collating name? highest collating name? longest name? shortest name?
The table includes info like:
Product; Compatible
iphone 4 car charger ; iphone 4
iphone 4 mains charger; iphone 4
iphone 4 usb cable; iphone 4
The DISTINCT way is not working. As I said in my first post I need the iphone 4 once. I do not have multiple compatible values. I need some code to say ‘if all results are the same, use only once’!
yes - exactly - in the navigation bar they might click iphone 4 and get the navigation above or they might click iphone 3 and get that list of accessories instead. But my problem is with the heading…like i say i cannot get it only once.,!
okay, i’m not a php developer so i can’t give you actual code, but let’s go back to what you said you wanted –
the first line, which contains the compatible name, you don’t have to retrieve this from the database because you already know what it is – it’s the value in your GET
the remaining lines simply pull out the products for that compatible, and here all you need is a simple query, no DISTINCT required –
SELECT name
FROM products
WHERE compatible = '".$_GET['compatible']."'" )