viiii
viiii

Reputation: 1227

How do i display the information of foreign key instead of id in MySQL and PHP?

just like the caption, how do i fetch information from foreign key instead of id?

Here are the first table:

enter image description here

and here are the second table: enter image description here

i want to display product_name and unit_price instead of id, how to do it?

Upvotes: 0

Views: 944

Answers (1)

Dokik
Dokik

Reputation: 364

You need to use join Your query should look something like this:

SELECT ft.id, pr.product_name, pr.unit_price from firsttable as ft join product as pr on ft.product_id = pr.product_id; 

Where firsttable is the table of the first screenshot and product is the table from the second screenshot. I don't know what you need from the first table so I just took a column id, however I do not know if you have this column. Here you just put whatever you need from the first table.

Upvotes: 1

Related Questions