[英]PHP MYSQL JOIN QUERY 2 Databases, Where table1.id = table2.id, How to display table2.content as table1.id
Im trying to put together a script that allows me to display links dynamically on my site.我试图组合一个脚本,允许我在我的网站上动态显示链接。
I have 2 tables.我有 2 张桌子。 The first one,
domains
can have two values per row.第一个,
domains
每行可以有两个值。 These being, domId
and domain
.这些是
domId
和domain
。 The next table, links
can contain a few values per row, the ones im working with here are domId
(matches the domId of the domains
table) desc
and `link'.下一个表,
links
每行可以包含几个值,我在这里使用的是domId
(匹配domains
表的 domId) desc
和“链接”。
Here is my query so far:到目前为止,这是我的查询:
$linkQuery2 = 'SELECT `link`,`desc`,`domId`
FROM `links`
WHERE `catId`="'.$pageCat.'"
&& (`modId`="1" || modId="'.$pageModel.'")
ORDER BY `domainId` ASC
LIMIT ' . $from . ', ' . $max_results2;
Here is the code that im using to display the info i need:这是我用来显示我需要的信息的代码:
$linkLoop2 = '';
$linkAd = $row['link'];
$linkDesc = stripslashes($row['desc']);
$linkDomain = stripslashes($row['id']);
$linkLoop = '<ul class="bymodel-dllinks">';
$linkLoop2 .= '<li><a href="'.$linkAd.'" target="_tab">'.$linkDesc.' '.$linkDomain.'</a></li>';
$linkLoop3 = '</ul>';
What I am trying to do is find a way so that when $linkDomain is echo'd it will display the text i have stored in the domain
field on the domains
table.我正在尝试做的是找到一种方法,以便在回显 $linkDomain 时,它将显示我存储在
domains
表的domain
字段中的文本。 Currently when $linkDomain
is echo'd, it will display 303, which is the domId
of the site i will be linking to.目前,当
$linkDomain
被回显时,它将显示 303,这是我将链接到的站点的domId
。
Use Join to select domain name from domainstable:使用从 domaintable 加入 select 域名:
$linkQuery2 = 'SELECT l.link,l.desc,l.domId,d.domain
FROM links l LEFT JOIN domains d ON d.domid = l.domid
WHERE l.catId="'.$pageCat.'"
&& (l.modId="1" || l.modId="'.$pageModel.'")
ORDER BY l.domainId ASC
LIMIT ' . $from . ', ' . $max_results2;
Add the domain
column to your select statement.将
domain
列添加到您的 select 语句中。
$linkQuery2 = 'SELECT `link`,`desc`,`domId`,`domain`
FROM `links`
WHERE `catId`="'.$pageCat.'"
&& (`modId`="1" || modId="'.$pageModel.'")
ORDER BY `domainId` ASC
LIMIT ' . $from . ', ' . $max_results2;
Change $linkDomain
to将
$linkDomain
更改为
$linkDomain = stripslashes($row['domain']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.