It all depends on your approach, but generally the availability table has three columns:
Language: PHP
`avail_id` int(11) DEFAULT NULL,
`model_id` int(11) NOT NULL,
`colour_id` int(11) NOT NULL
If there is a row in this table, then clearly this model is available in this colour - you do not have yes or no in this table. So models (by their model_id) that are not in this table is not available in any colour.
No there are many options available here, and I cannot give the correct approach as I want to see how you approach it (I am lenient here).
I will provide code that someone submitted that thought was quite novel
Language: PHP
for($i=1; $i<20; $i++){ //Start for loop for 19 models that I know I have inmodel table
for ($i2=1; $i2<7; $i2++){ //Start for loop inside MODEL for loop to for eac colour that there is.
//query model table to get the model name where model_id=$1
//query colour table to get the colour name where model_id=$i2
//query availability where the model_id=$1 and colour_id=$i2
//get the num of rows of the query, If there is a row, then set a var (say $is_avail) to yes, else no.
//echo the results e.g. model name, model color, $is_avail
}
}
echo "</table>";
There are much better ways of course, and using OOP is premium. For now, I want you to use whatever logic required to create the table