-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"

4
  • 1
    What on earth is this supposed to mean?: $row['datum'] <=0 $monate[$i][2] That's your syntax error. Commented May 4, 2016 at 10:25
  • Spurious 0 in && $row['datum'] <=0 $monate[$i][2] Commented May 4, 2016 at 10:26
  • Thanks yeah it seems to be that there was an unexpected 0 Commented May 4, 2016 at 10:28
  • Please dont use the mysql_ database extension, 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 Commented May 4, 2016 at 10:32

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah thanks if forgot that there was a 0 :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.