From the database, extract only those rows that have red, blue, green or yellow in field1, and blank in field4.
Loop through the result set, and do whatever you want with the results.
I’m afraid I can do nothing about how the data is entered into the database.
Yeah its the sql query part that I’m struggling with.
The code I was trying to get to work is below:
<?php $usedquery = mysql_query("SELECT DISTINCT Vehicle_Id, Full_Registration FROM Used_Stock WHERE Picture_Refs='' AND Colour LIKE '%red%' OR '%blue%' OR '%green%' ORDER BY Full_Registration ASC");
while($row_used = mysql_fetch_array($usedquery)){
echo ?>
<option value="<?php echo $row_used['Full_Registration']; ?>"><?php echo $row_used['Full_Registration']; ?></option>
<?php }; ?>
SELECT DISTINCT
Vehicle_Id
, Full_Registration
FROM Used_Stock
WHERE Picture_Refs='' AND
(Colour LIKE '%red%' OR
Colour LIKE '%blue%' OR
Colour LIKE '%green%'
)
ORDER BY Full_Registration ASC
It may be helpful to see why your code didnt work… here’s how mySQL saw your query. I’ve added comments on the end of the lines to show the ‘thought’ process of the server
SELECT DISTINCT Vehicle_Id, Full_Registration //Okay, those two fields.
FROM Used_Stock //Single table. No problem.
WHERE Picture_Refs='' //Null. Okay. Could be IS NULL as well.
AND Colour LIKE '%red%' //Sure.
OR '%blue%' //Huh? Thats not a logical test.
OR '%green%' //Huh? Thats not a logical test either.
ORDER BY Full_Registration ASC //Okay.