0

i want to select attendance details of an employee on the basis of months selected. i want to store data of each month with object name same as month. i don't understand how to assign name at run time. here is my code given below

 for ($i=0; $i < $totalmonth; $i++) { 


  $query="SELECT attendance FROM attendance
    WHERE month='$m' && year='$y' && dept='$dept' && location='$loc'";

    $result = mysqli_query($connect, $query);
    if(mysqli_num_rows($result) > 0)
      {
          $dbdata = array();
          while ( $row = $result->fetch_assoc())
          {
               array_push($dbdata, $row);
          }
       }
    else
      {
         echo 'Data Not Found';
      }
         echo json_encode(array('data' => $dbdata));

    }
1
  • You want this "Jan"=>data of jan?? Commented Feb 28, 2020 at 4:42

1 Answer 1

1

Use associative array to assign name of month as key in the code just like below;

while ( $row = $result->fetch_assoc())
{
     $dbdata[$m]=$row;  
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.