try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT ID, Nome, Apelido, Hora_Partida, Voo_Partida, Proveniencia_Partida, Data_Partida, Destino_Partida, Descricao_Partida, Motorista_Partida FROM asspartidas WHERE Nome = '$name'");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows2(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
/*
$block_rep='0000-00-00';
$stmt = $conn->prepare('SELECT FROM assistencia WHERE Data_Partida= :rep');
$bind = $stmt ->bindValue(':rep', $block_rep, PDO::PARAM_INT);
$stmt -> execute();
<!DOCTYPE html>
<html lang="pt">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta charset="UTF-8"/>
<html>
<head>
<meta charset="UTF-8">
<title>Consulta pelo Nome do Passageiro</title>
<h4>Chegadas</h4>
</head>
<style>
table {
width: 100%;
border: 1px solid black;
}
td {
border: 1px solid black;
height: 15px;
}
th {
border: 1px solid black;
height: 15px;
text-align: center;
}
table.TableRows {
table-layout: auto;
}
table.TableRows2 {
table-layout: auto;
}
</style>
<body>
<?php
echo "<table style='border: solid 1px black;'>";
echo "<tr><th>ID</th><th>Nome</th><th>Apelido</th><th>Hora</th><th>Voo</th><th>Proveniencia</th><th>Data</th><th>Destino</th><th>Descricao</th><th>Motorista</th></tr>";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width:95px;border:1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "\n";
}
}
if($_SERVER["REQUEST_METHOD"]=="POST"){
//collect value of input field
$name = $_POST["Primeiro"];
//fim da recolha do front in
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "operacoes";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT ID, Nome, Apelido, Hora_Chegada, Voo_Chegada, Proveniencia_Chegada, Data_Chegada, Destino_Chegada, Descricao_Chegada, Motorista_Chegada FROM asschegadas WHERE Nome = '$name'");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
}
?>
<h4>Partidas</h4>
<?php
echo "<table style='border: solid 1px black;'>";
echo "<tr><th>ID</th><th>Nome</th><th>Apelido</th><th>Hora</th><th>Voo</th><th>Proveniencia</th><th>Data</th><th>Destino</th><th>Descricao</th><th>Motorista</th></tr>";
class TableRows2 extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width:95px;border:1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "\n";
}
}
if($_SERVER["REQUEST_METHOD"]=="POST"){
//collect value of input field
$name = $_POST["Primeiro"];
//fim da recolha do front in
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "operacoes";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT ID, Nome, Apelido, Hora_Partida, Voo_Partida, Proveniencia_Partida, Data_Partida, Destino_Partida, Descricao_Partida, Motorista_Partida FROM asspartidas WHERE Nome = '$name'");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows2(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
/*
$block_rep='0000-00-00';
$stmt = $conn->prepare('SELECT FROM assistencia WHERE Data_Partida= :rep');
$bind = $stmt ->bindValue(':rep', $block_rep, PDO::PARAM_INT);
$stmt -> execute();
$assistencia=$stmt->fetchAll();
foreach($stmt as $dados){}
if($dados['Data_Partida'] == $block_rep){
}else{
echo $v;
}
*/
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
}
?>
<br><br>
<form method="post">
<input type="button" value="inprimir" onclick="window.print()"/>
</form>
</body>
</html>
Compartilhar este post
Link para o post
Compartilhar em outros sites