Skip to content
Advertisement

How do I display values from other tables in a database in php?

I am displaying all the items in my database table

There is a category table in my database as well that has these values

Table item has attributes(ItemID, Name, Price, categoryID(FK)) Table category has attributes(categoryID(PK), Name, Description)

JavaScript

Now when I display the items it gets displayed in this order

JavaScript

instead of the category ID I want the Category name to be displayed like this

JavaScript

Here is my SQL query that I have written

JavaScript

html part

JavaScript

Advertisement

Answer

You can add an alias in the second query:

JavaScript

And modify the Category column values:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement