-1

i have the problem, that i want to make an algorithm which reads the dates of every record from the database and check if it's the date from an array. When it's the right date, it will parse it to another array as the result.

$jahr = date("Y");
$monate = array(
          array("Jan", $jahr."-01-01", $jahr."-01-31"),
          array("Feb", $jahr."-02-01", $jahr."-02-29"),
          array("Mär", $jahr."-03-01", $jahr."-03-31"),
          array("Apr", $jahr."-04-01", $jahr."-04-30"),
          array("Mai", $jahr."-05-01", $jahr."-05-31"),
          array("Jun", $jahr."-06-01", $jahr."-06-30"),
          array("Jul", $jahr."-07-01", $jahr."-07-31"),
          array("Aug", $jahr."-08-01", $jahr."-08-31"),
          array("Sep", $jahr."-09-01", $jahr."-09-30"),
          array("Okt", $jahr."-10-01", $jahr."-10-31"),
          array("Nov", $jahr."-11-01", $jahr."-11-30"),
          array("Dez", $jahr."-12-01", $jahr."-12-31")
          );
$betrag = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0);

$select = "SELECT * FROM database WHERE userID=1";
$query = mysql_query($select);
while($row = mysql_fetch_array($query)) {
    for($i=0; $i<12; $i++) {
        if($row['datum'] >= $monate[$i][1] && $row['datum'] <=0 $monate[$i][2]) {
            $betrag[$i] += $row['betrag'];
        }
    }
}

The problem is, that i get this error message in the browser

Parse error: syntax error, unexpected '$monate' (T_VARIABLE) in test.php on line 29

line 29 is the line with the if statement

if($row['datum'] >= $monate[$i][1] && $row['datum'] <=0 $monate[$i][2]) {

In the msql database the row "datum" is formatted as "date"

Nils Blaumer
  • 19
  • 1
  • 6
  • 1
    What on earth is this supposed to mean?: `$row['datum'] <=0 $monate[$i][2]` That's your syntax error. – David May 04 '16 at 10:25
  • Spurious `0` in `&& $row['datum'] <=0 $monate[$i][2]` – Mark Baker May 04 '16 at 10:26
  • Thanks yeah it seems to be that there was an unexpected 0 – Nils Blaumer May 04 '16 at 10:28
  • Please dont use [the `mysql_` database extension](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), it is deprecated (gone for ever in PHP7) Specially if you are just learning PHP, spend your energies learning the `PDO` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly May 04 '16 at 10:32

1 Answers1

0
if($row['datum'] >= $monate[$i][1] && $row['datum'] <=0 $monate[$i][2]) {

specifically look at

$row['datum'] <=0 $monate[$i][2]

seems to be a typo of 0

Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
georoot
  • 3,557
  • 1
  • 30
  • 59