Question:
Hi, I have the following problem, I need to show a query that shows me the partners who have not paid for a certain course, but I have two fields called name, courses.name and partners.name, my problem is that when I run it, it shows me in the two fields partners.name
<?php
include ("conexion.php");
$sql="SELECT cursillos.codcurso, cursillos.nombre, socios.nombre from
cursillos inner join socios on cursillos.codcurso=socios.codcurso order
by cursillos.nombre";
$result=mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0){
echo "<h2><center>SOCIOS APUNTADOS</center></h2>
<table border='1' style='margin: 0 auto;'>
<thead>
<tr>
<th>CÓDIGO CURSO</th>
<th>NOMBRE CURSO</th>
<th>NOMBRE SOCIO</th>
</tr>
</thead>";
while($row = mysqli_fetch_assoc($result)) {
echo'
<tr>
<td><center>'.$row["codcurso"].'</center></td>
<td><center>'.$row["nombre"].'</center></td>
<td><center>'.$row["nombre"].'</center></td></tr>';
}
} else {
echo "0 resultados";
}
echo "</table></div>";
echo '<a href="consultaCursos.php">Volver al listado</a>';
mysqli_close($conn);
?>
Answer:
In the statement use as
to give it a new name:
SELECT cursillos.codcurso, cursillos.nombre as cNombre, socios.nombre as sNombre from
cursillos inner join socios on cursillos.codcurso=socios.codcurso order
by cursillos.nombre
And then access the array with the same name used:
<td><center>'.$row["codcurso"].'</center></td>
<td><center>'.$row["cNombre"].'</center></td>
<td><center>'.$row["sNombre "].'</center></td></tr>';
All the best!