My PDO statement returns 3 fields of data and displays the 3 field in a 3 column table:
I would like to adjust the code so the table displayed only has 2 columns.
This first column should display the country's flag instead of the name. The flag will be in the following folder site_url(); ?>/wp-content/gallery/Flags/'Country'.png
.
The second column should display BOTH First Name and Last Name.
<?php
//Table
echo "<table style='border: solid 1px orange;'>";
echo "<tr><th>Country</th><th>First Name</th><th>Last Name</th></tr>";
class TableRows extends RecursiveIteratorIterator
{
function __construct($it)
{
parent::__construct($it, self::LEAVES_ONLY);
}
function current()
{
return "<td style='width:150px;border:1px solid orange;'>".parent::current()."</td>";
}
function beginChildren()
{
echo "<tr>";
}
function endChildren()
{
echo "</tr>" . "
";
}
}
//Connection Info
//Connection Started, Data pulled
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$firstname = $_GET['fname'];
$stmt = $conn->prepare('SELECT Country, First_Name, Last_Name FROM tblPlayers WHERE First_Name = :fname');
$stmt->bindValue(':fname', $firstname, PDO::PARAM_INT);
$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;
}
}
//Error Check
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
// Take Text entry and fetch the SQL Row
//Kill Connection
$conn = null;
echo "</table>";
?>
Thanks for your help solving my problem.