0

So in my database, I have "due" and a date.

It is defined like this: $dues[$index] = $row["due"];

I want to echo how many days until that date, I have looked around but can't seem to find it from a database.

Tom
  • 1
  • 4

1 Answers1

0

In the database, you have a due and a date field. What's in the date field? Today's date? Pretty sure you don't even need that there and can just use today's date with php to calculate and echo the days until that date without even changing the database.

Since you already stored all your due values inside of the dues array, you can just echo in a table:

$array_size = count($dues);
echo '<table>';
for($i = 0; $i < $array_size; $i++) {
    // if your date is in the format mm/dd/yyyy...
    // (you can change it however you want according
    // to how you formatted it in your database).
    $today = date('m/d/Y');
    $daysuntil = (strtotime($dues[$i])-strtotime($today)) / 86400;
    echo '<tr><td>Due: '.$dues[$i].'</td>';
    echo '<td>'.$daysuntil.' days left</td></tr>';
}
echo '</table>';
YiJio
  • 49
  • 5