-4

So I'm having this issue where I want to echo only the things that are 1 higher or 1 lower then the current hour. Example if current hour = 14 only echo 13, 14 and 15

Anyone have a clue on how I can do this?

<?php 
mysql_connect("*******", "******", "**");
if(!mysql_select_db("deb67423_dj")) {
die("<b>Mislukt!</b><br>Het verbinden met de database is mislukt.");
}
$textweek = date("D");
if($textweek == "Mon") {
$dag = 0;
} else
if($textweek == "Tue") {
$dag = 1;
} else
if($textweek == "Wed") {
$dag = 2;
} else
if($textweek == "Thu") {
$dag = 3;
} else
if($textweek == "Fri") {
$dag = 4;
} else
if($textweek == "Sat") {
$dag = 5;
} else
if($textweek == "Sun") {
$dag = 6;
}
$textuur = date("G");

$SQL = "SELECT * FROM rooster WHERE dag = '$dag'";
$result = mysql_query($SQL);
echo "<table>";
while ($row = mysql_fetch_assoc($result)) {
    echo "<td> Hiervoor: DJ ".$row['gebruikersnaam']. "</td>";
}                   
echo "</table>";
Kevin Houghton
  • 45
  • 2
  • 10
  • 5
    What does the code have to do with your question? – Fabian Schmengler Feb 19 '13 at 14:39
  • This is what I have so far, but I have no clue on how to go further. – Kevin Houghton Feb 19 '13 at 14:40
  • 1
    1. Do you have a timestamp in your database? 2. Why aren't you using an array instead of 7 if sentences? 3. Why aren't you using `$dag = ((int)date("N") - 1);` instead? – h2ooooooo Feb 19 '13 at 14:43
  • 3
    Oh, and: [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – h2ooooooo Feb 19 '13 at 14:44

1 Answers1

1
$currHour = date('G');
echo $currHour - 1, ', ', $currHour, ', ', $currHour + 1;

Take note that $currHour can be 0 and you will have to take care of this "special" case... But I think this snippet will get you started. See the PHP date() documentation for more help.

AlexV
  • 22,658
  • 18
  • 85
  • 122