I am trying to display some query results from MySQL in a HTML table. I have tried to display the table in a new php page, which works fine. My problem is that I can't seem to find a way to display the table in the same html page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="relative.css" media="screen" />
</head>
<body>
<div class="cabecera">
<h1> GENUS </h1>
</div>
<ul id="menu">
<li><a href="profile.html">Perfil</a></li>
<li><a href="member.html">Nuevo pariente</a></li>
<li><a href="relative.html" class="relative">Parientes registrados</a></li>
</ul>
<?php
require_once 'connectbd.php';
$conn = connectbd();
session_start();
$escritor = $_SESSION["escritor"];
$sql="SELECT * FROM Pariente WHERE escritor_ID='$escritor' ";
$result= mysql_query($conn,$sql) or die(mysql_error($conn));
if(mysql_num_rows($result)==0) die("No hay registros para mostrar");
echo '<table border=1 cellpadding=4 cellspacing=0>';
echo '<tr>
<th colspan=5> Agenda personal </th>
<tr>
<th> ID </th><th> Nombre </th><th> Primer Apellido </th>
</tr>';
while($res=mysql_fetch_array($result))
{
echo'<tr><td>'.$res['nombre'].'</td><td>'.$res['primer_apellido'].'</td><td>'.$res['segundo_apellido'].'</td></tr>';
}
echo '</table>';
?>
<a href="logout.php"><input type="button" value="Cerrar sesión" /></a>
</body>
</html>
Here is my connectbd.php code:
<?php
class DB_Connect {
// constructor
function __construct() {
}
// destructor
function __destruct() {
// $this->close();
}
// Connecting to database
public function connect() {
require_once 'config.php';
// connecting to mysql
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
// selecting database
mysql_select_db(DB_DATABASE);
// return database handler
return $con;
}
// Closing database connection
public function close() {
mysql_close();
}
}
?>
EDIT: This is the table displayed: