Hi Guys!
I have a table with 2 rows.
1st row shows dates starting from today up to 20 days ahead. Each date in separate cell of the row. That works.
2nd row should take the date from the mysql database and check if it corresponds with the date in the cell above (from the first row of the table). If the dates match then echo ‘option 1’, if there is no match then echo ‘option 2’. But the echoing should take the place exactly under the matching date from the first row above.
I have tried various options but so far without success…
P.S. Connection with mysql database works fine and I can get the ‘date’ from it. In mysql table the date is formatted as DATE format: YYYY-MM-DD
Any suggestions?
Thanks, Raivis
[php]
// *** first row of the table ***
echo ‘
’;
date_default_timezone_set('UTC'); // Set timezone
$date = date('Y-m-d'); // Start date - to be displayed in the first table cell
$end_date = date('Y-m-d', strtotime('+20 days')); // End date - to be displayed in the last table cell
while (strtotime($date) <= strtotime($end_date)) {
$table_date = date('d',strtotime($date)) ;
echo '<td bgcolor="#999999" style="padding:2px;" >';
echo $table_date;
echo "</td>";
$date = date ('Y-m-d', strtotime('+1 day', strtotime($date)));
}
echo "</tr><tr>";
// *** second row of the table ***
include_once “…/scripts/connect_to_mysql.php”;
$sqlCommand = “SELECT date FROM janis ORDER BY date ASC LIMIT 21”;
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error($myConnection));
while($row = mysqli_fetch_array ($query)){
$datematch = $row['date'];
echo '<td bgcolor="#999999" style="padding:2px;" >';
if($datematch==$table_date){ // this was one of my versions to put the IF statement in - to check if date from first row matches the date from database
echo 'option 1';
} else {
echo 'option 2';
}
}
echo "</td>";
echo “
”;
mysqli_free_result($query); [/php]