Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL Left Join help
    primarykey
    data
    text
    <p>Hello again community,</p> <p>I posted a question just over an hour ago asking for some help fixing a SQL query, that was promptly answered and was a great help. Sadly though, upon reflection and further usage, it turns out that the query was returning all rows in the targeted table. I validated this by putting the mysql_fetch_object inside a while loop.</p> <p>So what I desperately need now is someone to have a look at the SQL query and tell me what is going wrong and if possible how to fix it. I simply just need one row (the correct row) to be found when using $_SESSION['model'] as the reference.</p> <p>Below is the full content of my previous question.</p> <p>Thank you in advance.</p> <p>============================================================================</p> <p>web_quote_models table</p> <pre><code>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 | 000004 | 1 | 4 | 4 | 4 | 4 | 4 </code></pre> <p>web_quote_component_cpu table</p> <pre><code>id | name ========================================================================== 1 | Intel&amp;reg; Core&amp;trade; i3 2100 3.1GHz dual-core 2 | Intel&amp;reg; Core&amp;trade; i5 2500 2.7GHz quad-core 3 | Intel&amp;reg; Core%trade; i7 2600 3.4GHz 8mb Cache dual-core </code></pre> <p>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.</p> <p>This is what I have so far; I cant be too far off I think.</p> <pre><code>(" 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']."' "); </code></pre> <p>A massive thank you in advance to anyone that helps.</p> <p>Dan.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload