Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading