Mostrar nome associado em vez de codconcelho
Ola a todos.
Eu tenho 2 tabelas no mysql, uma com o nome concelho e outra com o nome escolas e as linhas pertencentes são estas:
Tabela concelho:
(primary key) codconcelho;
nome;
Tabela escolas:
(primary key) codigo;
escola;
(secondary key ligada a codconcelho) concelho;
Eu tenho uma tabela que mostra os dados da tabela escola ao usar um recordset, mas eu
queria que em vez de mostrar o codconcelho associado na tabela concelho, mostrasse o nome.
O codigo e este:
<?php require_once('../Connections/ligbd.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_RsEscolas = 10;
$pageNum_RsEscolas = 0;
if (isset($_GET['pageNum_RsEscolas'])) {
$pageNum_RsEscolas = $_GET['pageNum_RsEscolas'];
}
$startRow_RsEscolas = $pageNum_RsEscolas * $maxRows_RsEscolas;
mysql_select_db($database_ligbd, $ligbd);
$query_RsEscolas = "SELECT * FROM escolas ORDER BY nome ASC";
$query_limit_RsEscolas = sprintf("%s LIMIT %d, %d", $query_RsEscolas, $startRow_RsEscolas, $maxRows_RsEscolas);
$RsEscolas = mysql_query($query_limit_RsEscolas, $ligbd) or die(mysql_error());
$row_RsEscolas = mysql_fetch_assoc($RsEscolas);
if (isset($_GET['totalRows_RsEscolas'])) {
$totalRows_RsEscolas = $_GET['totalRows_RsEscolas'];
} else {
$all_RsEscolas = mysql_query($query_RsEscolas);
$totalRows_RsEscolas = mysql_num_rows($all_RsEscolas);
}
$totalPages_RsEscolas = ceil($totalRows_RsEscolas/$maxRows_RsEscolas)-1;
mysql_select_db($database_ligbd, $ligbd);
$query_RsConcelho = "SELECT * FROM concelho";
$RsConcelho = mysql_query($query_RsConcelho, $ligbd) or die(mysql_error());
$row_RsConcelho = mysql_fetch_assoc($RsConcelho);
$totalRows_RsConcelho = mysql_num_rows($RsConcelho);
$queryString_RsEscolas = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_RsEscolas") == false &&
stristr($param, "totalRows_RsEscolas") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_RsEscolas = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_RsEscolas = sprintf("&totalRows_RsEscolas=%d%s", $totalRows_RsEscolas, $queryString_RsEscolas);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sem título</title>
<link href="../mm_health_nutr.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0">
<tr>
<td width="20"> </td>
<td class="pageName" width="180">Escolas...</td>
<td width="150"> </td>
<td width="300" align="right"><a href="insescolas.php">Insere novo</a></td>
</tr>
</table>
<table width="650" border="0">
<tr>
<td width="20"> </td>
<td>
<?php if ($totalRows_RsEscolas > 0) { // Show if recordset not empty ?>
<p class="bodyText">Registros <?php echo ($startRow_RsEscolas + 1) ?> a <?php echo min($startRow_RsEscolas + $maxRows_RsEscolas, $totalRows_RsEscolas) ?> de <?php echo $totalRows_RsEscolas ?>
</p>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="200" class="subHeader">Código</td>
<td width="250" class="subHeader"><strong>Escola</strong></td>
<td width="250" class="subHeader">Concelho</td>
</tr>
<?php do { ?>
<tr>
<td><?php
echo $row_RsEscolas['codigo'];
$cc=$row_RsEscolas['codigo'];
?></td>
<td><a href="verescolas.php?cd=<?php echo"$cc";?>"><?php echo $row_RsEscolas['nome']; ?></a></td>
<td><?php echo $row_RsConcelho['nome']; ?></td>
</tr>
<?php } while ($row_RsEscolas = mysql_fetch_assoc($RsEscolas)); ?>
</table>
<table border="0">
<tr>
<td><?php if ($pageNum_RsEscolas > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_RsEscolas=%d%s", $currentPage, 0, $queryString_RsEscolas); ?>">Primeiro</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_RsEscolas > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_RsEscolas=%d%s", $currentPage, max(0, $pageNum_RsEscolas - 1), $queryString_RsEscolas); ?>">Anterior</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_RsEscolas < $totalPages_RsEscolas) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_RsEscolas=%d%s", $currentPage, min($totalPages_RsEscolas, $pageNum_RsEscolas + 1), $queryString_RsEscolas); ?>">Próximo</a>
<?php } // Show if not last page ?></td>
<td><?php if ($pageNum_RsEscolas < $totalPages_RsEscolas) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_RsEscolas=%d%s", $currentPage, $totalPages_RsEscolas, $queryString_RsEscolas); ?>">Último</a>
<?php } // Show if not last page ?></td>
</tr>
</table>
<?php } // Show if recordset not empty ?>
<?php if ($totalRows_RsEscolas == 0) { // Show if recordset empty ?>
<p class="bodyText">Ainda não Existem Escolas</p>
<?php } // Show if recordset empty ?>
</td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($RsEscolas);
mysql_free_result($RsConcelho);
?>Discussão (1)
Carregando comentários...