How to form this result so that I can pad 0 to id

I have this working code

            $res = $this->connection->prepare("....");

            $result = $res->fetchAll(PDO::FETCH_ASSOC);

            $data = array(

            return json_encode($data);

And this is the result

{“data”:[{“id”:“10”,“time_in”:“2015-07-06 07:30:00”,“time_out”:“2015-07-06 10:26:11”
,“attended”:“yes”},{“id”:“9”,“time_in”:“2015-07-06 08:00:00”,“time_out”:“2015-07-06

But I want my result id to have padded 0, how can I achieve to have this output with padded 0

{"data":[{"id":"00010","time_in":"2015-07-06 07:30:00","time_out":"2015-07-06 10:26:11"
  ,"attended":"yes"},{"id":"00009","time_in":"2015-07-06 08:00:00","time_out":"2015-07-06

I know how to put padded 0 if I will use the while loop


but I cannot output same format above.

best is to do that in SQL.

for MySQL that would be LPAD(id, 5, '0') AS id

1 Like

Thank you it works.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.