Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从id相同的其他表中提取名称/值_Php_Mysql_Sql_Select - Fatal编程技术网

Php 从id相同的其他表中提取名称/值

Php 从id相同的其他表中提取名称/值,php,mysql,sql,select,Php,Mysql,Sql,Select,分销商表 name id usf south 1 usf north 2 usf east 3 usf west 4 ogi表 distributor itemname 1 cheese 1 apples 3 oranges 2 pineapples 目前,我在“ogi表”的“distributor”列中为页面上的每个itemna

分销商表

name          id
usf south     1
usf north     2
usf east      3
usf west      4
ogi表

distributor    itemname
1              cheese
1              apples
3              oranges
2              pineapples
目前,我在“ogi表”的“distributor”列中为页面上的每个itemname显示了编号。但是,我想将此编号更改为“distributors表”中的正确分销商名称。我该怎么做


感谢您的帮助。

本教程将向您展示如何将其存档

要全面了解加入,请访问以下链接:


如果您只想替换查询而不想替换下划线编程,这可能是一个可行的解决方案:

SELECT
    ogi.itemname,
    distributors.name AS distributor
FROM
    ogi
INNER JOIN
    distributors
    ON
    ogi.distributor = distributors.id

+1用于格式良好的示例。这是完美的。不需要修改我的任何php代码。谢谢你的帮助!我认为这是一个内部连接,但我不太确定如何实现它(对mysql来说有点新)。再次感谢!
SELECT
    ogi.itemname,
    distributors.name AS distributor
FROM
    ogi
INNER JOIN
    distributors
    ON
    ogi.distributor = distributors.id