• Hello, I would like to get results from the following design in the style “Prague 110 00”, “Brno 620 00” (now “Prague” “110 00” “Brno” “620 00”). Would anyone please advise on how to do this? Thanks in advance!

    $sql = "SELECT * FROM `kontakty` WHERE `name` = 'mesto' OR `name` = 'psc'";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
      while($row = $result->fetch_assoc()) {
        echo json_encode($row["value"]);
      }
    } else {
        echo "0 results";
    }
    $conn->close();
    • This topic was modified 8 years, 4 months ago by bcworkz. Reason: fix query whith entity codes
Viewing 3 replies - 1 through 3 (of 3 total)
  • I think the best option is to concatenate these fields right on the query.

    Could you provide the fields names so I can try to build the query as I said?

    Thread Starter ferda2

    (@ferda2)

    This is the Advanced CF7 DB Advanced Table (s). The Name column contains all field data. From the name column, I need to get the values of the city (city) and psc (zip) fields. It works, but I need to list “Prague 110 00”, “Brno 620 00”, etc. Thanks for your help.

    Moderator bcworkz

    (@bcworkz)

    I don’t know how one would combine fields within the query, but combining in PHP is straight forward enough. You need some sort of loop counter in order to keep track of odd or even counts. You could do a for loop instead of while, incrementing by 2. Or just keep a counter (starting at 0) incrementing within the while loop, and using the count modulo 2 result to determine odd or even.

    On zero and even count loops, assign $row[“value”] to a variable for use in the odd loop. Let’s use $city as an example. Then in the odd loops, do echo json_encode( $city . ' ' . $row['value']);

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Merge multi-value results from one column (PHP array)’ is closed to new replies.