0

what I am trying to do is extract elements of an array and running an sql query with the array element as the condition. The problem what I am facing is that the query does not return anything. The code is given below

//extracting the array elements
      foreach ($t as $value) {
      extract($value);

     }
 $sql = "SELECT * FROM daily_log where employee_log_id='$employee_log_id' AND log_date='$value'</br>";
            $result = mysql_query($sql);
            $row = mysql_fetch_array($result);
        echo $row['in_time'];
        echo $row['out_time'];

The echo $row['in_time'] and echo $row['out_time']; does not show anything.

Can anybody help me to figure out what the problem is Thanks in advance.

1 Answer 1

0

The problem is your sql query code is outside the foreach loop. The $value variable doesn't exist in that scope.
Try this:

foreach ($t as $value) {
    extract($value);
    $sql = "SELECT * FROM daily_log where employee_log_id='$employee_log_id' AND log_date='$value'</br>";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    echo $row['in_time'];
    echo $row['out_time'];
}

EDIT:
But I can't understand what you are trying to do. I think you either need the extract() function or the foreach loop. Also, why is there a </br> html tag in your sql query string?
Do you want something like this?

foreach ($t as $key -> $value) {
    $sql = "SELECT * FROM daily_log where employee_log_id='$key' AND log_date='$value'";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    echo $row['in_time'];
    echo $row['out_time'];
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.