嗯,我一直試圖在整個下午/晚上處理這個問題,並且我知道我已經接近...仍然無法正確解決問題:/INNER JOIN後表格中的字段顯示不正確 - 未定義索引
我有一個數據庫(因爲我學習使用它與phpMyAdmin創建),它具有學科和職業,而像ID,名稱,描述等領域
表科目都有一個id和來自表Careers(職業編號)的外鍵。我已經做了在phpMyAdmin使用的關係圖。
然後......我對主頁的主PHP文件(如「家」),並在那裏我已經包括到另一個PHP文件的鏈接,顯示了所有科目的表(名稱主題,描述,時間,職業,和動作)
這是Home.php表部分:
<table class="table table-striped table-bordered table-hover tabla">
<thead>
<tr>
<th class="thead_texto">Subject</th>
<th class="thead_texto">Description</th>
<th class="thead_texto">Hours</th>
<th class="thead_texto">Carrer</th>
<th class="thead_texto">Actions</th>
</tr>
</thead>
<tbody><!-- Loop for the subjects -->
<?php
include("../extras/tablaSubjects.php");
?>
</tbody>
</table>
這是PHP文件,顯示與由受試者和交易信息數據庫:
<!-- This comes from another file that have the info for the conection -->
<?php
include("conexion.php");
//Conection
$CONN = new mysqli($serverName, $username, $password, $dataBase);
//Checking
if ($CONN->connect_error){
echo("Error de conexion");
}
else{
echo "Conectado";
}
//Showing the subjects and information
//Query to select
$SQL = "SELECT s.id, s.name, s.description, s.hours, c.name FROM subjects m JOIN careers c ON (s.career_id = c.id)";
$resultado = $CONN->query($SQL);
//Part of the tbody where the loop will be
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
echo "<tr>";
echo "<td>{$row['s.name']}</td>";
echo "<td>{$row['description']}</td>";
echo "<td>{$row['hours']}</td>";
echo "<td>{$row['name']}</td>";
echo '<td><a class="btn btn-primary" value="'.$row['id'].'">Edit</a> <a class="btn btn-danger" value="'.$row['id'].'">Delete</a> </td>';
echo "</tr>";
}
}else{
echo "<tr><td>No data<td></tr>";
}
?>
它實際上工作正常,試着展現對象的名稱時除外:/ 在這一部分:
echo "<td>{$row['s.name']}</td>"; --> this gives an error, "Undefined index"
echo "<td>{$row['description']}</td>"; --> OK, info from SUBJECT
echo "<td>{$row['hours']}</td>"; --> OK, info from SUBJECT
echo "<td>{$row['name']}</td>"; --> This displays the name of the CAREER :/
我似乎無法理解爲什麼它顯示從主題和甚至所有數據職業的名稱,但不是主題的名稱:/ 如果我寫它的名字,它仍然顯示了職業生涯的名稱。 如果我寫「subject.name」,仍然說「未定義索引」
這與PhpMyAdmin應用程序有什麼關係?你有你自己的PHP腳本,你沒有使用該工具。 – Barmar
難道不應該是'科目s',而不是'科目M'? – Barmar
@Barmar嗨!是的,事情是我翻譯了整個事情,讓人們理解它哈哈我實際上使用西班牙語,所以「主題」是「materias」,所以使用m。我忘了在這裏改變它xD – xragdollqueen