Jump to content

Select name from a table!


z4z07
Go to solution Solved by Barand,

Recommended Posts

Hi guys!

 

I have 2 mysql tables 1 named categories and the other one named products. In the first table i have cat_id, cat_name and in the secoudn one i have product_id, product_name, product_price, cat_id

 

Now on the product page where i have my product listed i wanna display the cat_name based on the cat_id wich is present in both tables. What is the correct mysql syntax for this.

 

Thank you very much.

Link to comment
Share on other sites

I've tried somehting like this:

<?php $result = mysqli_query($conn, "SELECT cat_name FROM domeniu_activitate INNER JOIN user_pers_juridica WHERE cat_id LIKE cat_id AND product_id = '$id'"); while($row = mysqli_fetch_array($result))
{
echo $row['cat_name'];
}
?>
Link to comment
Share on other sites

  • Solution

Your join syntax is wrong.

SELECT cat_name 
FROM domeniu_activitate d
INNER JOIN user_pers_juridica u
    ON d.cat_id = u.cat_id  
WHERE product_id = '$id'

It is also better to use prepared queries. You should not be putting data ($id) directly into your queries.

Edited by Barand
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.