I have been working on learning PDO. Basically what I am trying to do is display names that are off work on any given day of the year.
I created a prepared statement that gives me the names, based on a date set in a variable. It's working as expected.
The problem I am having is displaying that on a seperate page. Lets say my page with the PDO statement is called vacationnames.php
Depending on the date I need to display those names on 1 of 4 different pages called calendar1.php or calendar2.php...etc.
Here is the code I have: vacationnames.php
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$db = new PDO($dsn, $user, $pass, $opt);
$sth = $db->prepare("
SELECT (employee.name)Name
, vacation_picks._date1 as Date
FROM employee
LEFT OUTER JOIN
vacation_picks on
employee.employee_id = vacation_picks.employee_id
WHERE vacation_picks._date1 = :day
");
This is on one of the calendar.php pages
$myVariable = ('2017-1-1');
// This executes the SQL query, binding the parameter as we go.
$sth->execute(array(
':day' => $myVariable
));
// echo $myVariable;
foreach($sth as $row) {
echo $row['Name'];
}
Even putting the 'Day One' php on calendar.php with vacationnames.php required_once gives me no result. I would prefer to have it referenced with even less code on calendar.php if possible.
Thanks for looking.