简体   繁体   English

如何从其他表(其中主键是外键)添加动态文本到所显示的动态表?

[英]How can I add dynamic text from a different table where primary key is a foreign key to adynamic table being shown?

I have here a dynamic table named tb_user with column region_id and institute_id and both ids are primary key of another table tb_region (with column region_name and region_id) and tb_institute (column institute_id and institute_name). 我在这里有一个名为tb_user的动态表,该表的列为region_id和Institute_id,两个ID都是另一个表tb_region(列为region_name和region_id)和tb_institute(列的Institute_id和Institute_name)的主键。 I wanted to see region_name and institute_name instead of the ids. 我想查看region_name和Institute_name而不是ID。

I've used this php script 我用过这个php脚本

<?php echo $row_institute['institution_name']; ?>

and query to collect data for tb_institute 并查询以收集tb_institute的数据

mysql_select_db($database_connection_ched, $connection_ched);
$query_institution = "SELECT institute_id, institute_name FROM   tb_institute";
$institution = mysql_query($query_institution, $connection_ched) or die(mysql_error());
$row_institution = mysql_fetch_assoc($institution);
$totalRows_institution = mysql_num_rows($institution);

but it seems not to display the correct name of id. 但似乎没有显示正确的ID名称。

query i used to collect data: 我用来收集数据的查询:

mysql_select_db($database_connection_ched, $connection_ched);
$query_notification = sprintf("SELECT * FROM tb_user WHERE status = 'inactive' ORDER BY     date_register ASC", GetSQLValueString($colname_notification, "text"));
$query_limit_notification = sprintf("%s LIMIT %d, %d", $query_notification,     $startRow_notification, $maxRows_notification);
$notification = mysql_query($query_limit_notification, $connection_ched) or die(mysql_error());
$row_notification = mysql_fetch_assoc($notification);


if (isset($_GET['totalRows_notification'])) {
  $totalRows_notification = $_GET['totalRows_notification'];
} else {
  $all_notification = mysql_query($query_notification);
  $totalRows_notification = mysql_num_rows($all_notification);
}
$totalPages_notification = ceil($totalRows_notification/$maxRows_notification)-1;
$row_institution['institute_name']

代替

$row_institute['institution_name']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM