This code works.
... $se = $conn->query("SELECT ... ;"); $se ->setFetchMode(PDO::FETCH_ASSOC); $n = 1; while($row = $se->fetch()) { $x=$x.'"'.$n++.'":"'.$row[p1].'","'.$n++.'":"'.$row[p2].'",'; $c1 = $row[c1]; $c2 = $row[c2]; $c3 = $row[c3]; } ... Select returns a table in which the columns c1, c2, c3 always have the same values. If I understood correctly, then the variable “under json” is formed in the loop. And in the same cycle, at each iteration, the variables c are assigned the same values. How to carry out such assignment for a cycle?