[英]Using 2 equal fields in 2 different databases databases PHP
我会尽量解释清楚。 我正在创建一个翻译函数,它基于每个具有代码值的文本。 例如:某个页面的标题具有代码和与代码关联的值。
我有 2 个表:translations:保存所有代码和值的表和一个表,其中只有代码本身,它通过一个函数将它通过转换表:
public function T($code) {
$value = $code;
$db_value = $this->db->getRow("SELECT value FROM translations WHERE code = '".$code."'");
if($db_value) {
$value = $db_value['value'];
}
return $value;
}
GetRow 是一个从表中选择单列的自定义函数:
function getRow() {
$func_num_args = func_num_args();
$func_get_args = func_get_args();
if ($func_num_args == 0) {
return null;
} else if ($func_num_args == 1) {
$this->query($func_get_args[0]);
} else {
$args = array();
$query = $func_get_args[0];
unset($func_get_args[0]);
foreach ($func_get_args as $arg) {
if (is_string($arg) && !is_numeric($arg)) {
$args[] = mysqli_real_escape_string($this->conn, $arg);
} else {
$args[] = $arg;
}
}
$this->query(vsprintf($query, $args));
}
return ($this->rows() ? $this->fetch() : null);
}
现在制作网站的管理页面时遇到问题,我希望隐藏文本代码并显示代码代表的文本。 我当前的选举看起来有点像这样:但是它不起作用,它只选择列但没有找到任何行:
SELECT vc.*,
t.code,
t.value
FROM vakances_card AS vc
JOIN translations AS t
ON vc.title = t.code
AND vc.descr = t.code
我不确定你到底想达到什么目的。 您可以将查询更改为
SELECT vc.*,
t.code,
t.value
FROM vakances_card AS vc
JOIN translations AS t
ON vc.title = t.code
AND vc.descr = t.code
到以下查询
SELECT vc.*,
t.code,
t.value
FROM vakances_card AS vc
LEFT JOIN translations AS t
ON vc.title = t.code
AND vc.descr = t.code
或者可以改为
SELECT vc.*,
t.code,
t.value
FROM vakances_card AS vc
RIGHT JOIN translations AS t
ON vc.title = t.code
AND vc.descr = t.code
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.