Hi,

I think by now I have the right syntax for joining 3 tables, but please correct me if it is wrong.

The tables I am joining a as follows:
PRODUKTER (GENERAL PRODUCT INFORMATION)
VARE_TYPE (SHIRTS, JEANS ETC)
SIZES (PRODUCT SIZES)

What I want to do is to let the admin update stock for his shop in one query where I am joining these 3 tables.
I am not sure what result-set i get in return or how to get it actually.

This is what I have: (which gives me an empty result set?)

function lager_styring($connection)
{
if (isset($_GET['produkt_id']))
{
$P_ID = mysqli_real_escape_string($connection, $_GET['produkt_id']);	
}

$get_produkt_info = mysqli_query($connection, "
SELECT produkter.id, produkter.brand_id, produkter.varetype_id, produkter.stock 
INNER JOIN vare_type ON (produkter.varetype_id = vare_type.id)
INNER JOIN sizes on (produkter.id = sizes.produkt_id) 
WHERE produkter.id = '".$P_ID."'");

while ($produkt_row = mysqli_fetch_array($get_produkt_info))
{
echo 'Produkt Id = '.$produkt_row['id'].'<br />'; // From produkter
echo 'Produkt Brand Id = '.$produkt_row['brand_id'].'<br />'; // From produkter
echo 'Produkt Vare type Id = '.$produkt_row['varetype_id'].'<br />'; // From produkter
echo 'Produkt On Stock = '.$produkt_row['stock'].'<br />'; // From produkter
echo 'Produkt name = '.$produkt_row['navn'].'<br />'; // From vare_type (Jeans, shirts)
echo 'Produkt Sizes = '.$produkt_row['size'].'<br />'; // All sizes from the sizes table
}

I get this warning, but need help to get the resutlset - Am I way off?

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\newshop\backend\functions\functions.php on line 317
}

where is the `from` clause in your select query?

commented: Totally missed it... +14
commented: doh, he got it +3

Update line 8 to this and it will tell you if theres an error

$get_produkt_info = mysqli_query($connection, "
SELECT produkter.id, produkter.brand_id, produkter.varetype_id, produkter.stock 
INNER JOIN vare_type ON (produkter.varetype_id = vare_type.id)
INNER JOIN sizes on (produkter.id = sizes.produkt_id) 
WHERE produkter.id = '".$P_ID."'") or die(mysqli_error($connection));

Thanks karthik Pranas!

Im only at the stage of trying to learn how to use joins - putting in FROM sorted the problem out - Thank you for helping out :-)

I thought that when writing:

SELECT produkter.id etc etc

SQL would automatically take the table called produkter since I wrote produkter.column_name

But thank you for pointing that out!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.