I am having trouble working out how to return the correct row in a table given that said table is relational. The two tables are shown below.
web_quote_models table
id | model | product_id | cpu_id | ram_id | hdd_id | os_id | opt_id
=========================================================================
1 | 000001 | 1 | 1 | 1 | 1 | 1 | 1
2 | 000002 | 1 | 2 | 2 | 2 | 2 | 2
3 | 000003 | 1 | 3 | 3 | 3 | 3 | 3
4 | Custom | 0 | 0 | 3 | 4 | 4 | 4
web_quote_component_cpu table
id | name
=========================================================================
1 | Intel® Core™ i3 2100 3.1GHz dual-core
2 | Intel® Core™ i5 2500 2.7GHz quad-core
3 | Intel® Core%trade; i7 2600 3.4GHz 8mb Cache dual-core
So what I need to achieve is a query that will look inside the web_quote_models table and match the model field with a $_SESSION[‘model’] then match the web_quote_models.cpu_id field with the web_quote_component.id.
This is what I have so far; I cant be too far off I think.
("
SELECT web_quote_component_cpu.name
FROM web_quote_component_cpu
LEFT JOIN web_quote_models
ON web_quote_component_cpu.id='web_quote_models.cpu_id'
AND web_quote_models.name='".$_SESSION['model']."'
");
A massive thank you in advance to anyone that helps.
Dan.
I don’t think you’re far off at all. I believe that all you need to do is stop quoting
web_quote_models.cpu_id:Edit
Based on the comment, I would personally re-write the query:
Though I would suspect that swapping that last
ANDwith aWHEREwould be sufficient: