HiDayurie Dave
HiDayurie Dave

Reputation: 1807

PHP JSON data value all same

I'm on PHP JSON query with database.

$qAdzanIqomah = mysqli_query($con, "SELECT * FROM tb_sholat WHERE active = 'Y'");
while($dAdzanIqomah = mysqli_fetch_array($qAdzanIqomah))
{
    $sholatName[] = $dAdzanIqomah['sholat_name'];

    $audio_before_adzan[] = $dAdzanIqomah['audio_before_adzan'];

    $iq = $dAdzanIqomah['iqamah'];

    echo $iqamahC[] = date("H:i:s", strtotime("+ '" . $iq . "' minutes"));
}

$data = array(
    'iqamah' => $iqamahC
);

echo json_encode($data);

The problem is, all the result is same even on table data is variations.

Result echo $iqamaC[]:

{"iqamah":["01:00:00","01:00:00","01:00:00","01:00:00","01:00:00"]}

-

01:00:00
01:00:00
01:00:00
01:00:00
01:00:00

Result echo $iq:

11
12
17
13
10

Is there something wrong with that code?

Upvotes: 2

Views: 61

Answers (1)

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72299

You have unnecessary quotes and spaces in the minute-adding code, and that is the actual cause of the issue (failing to add minutes)

Remove unnecessary quotes like below:-

$iqamahC[] = date("H:i:s", strtotime("+$iq minutes"));

And check.

A demo working example:-https://eval.in/891471

Upvotes: 3

Related Questions