0

About this question marked as duplicate, I wasn't asking about how to encode in the original question, the encoding was the answer to the question though.

In my php I've filled an array with data from a database (each object in the array is the row, stored as another array). I'm calling echo json_encode($json); so I can grab it through android but it doesn't output anything. I can call each array and every column like echo $json[#][#]; and get the expected result, so I know the arrays are filled. How do I get it all out there so people can touch it with their greedy little fingers?

php:

<?php
    $host="HOST";
    $username="USER";
    $password="PASS";
    $db_name="DATABASE";

    $con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    $sql = "SELECT * FROM Table WHERE Column = 1";
    $result = mysql_query($sql);
    $json = array();
    if(mysql_num_rows($result))
    {
        while($row=mysql_fetch_assoc($result))
        {
            $json[] = array($row['col1'], $row['col2'], $row['col3'], $row['col4'], $row['col5'], $row['col6']);
        }
        echo json_encode($json);
    }
?> 

SOLVED The problem was with UTF8, on some columns that have text, occasionally specail characters are used (in this case, Å, Ä and Ö). Thanks to commenter @meda that suggested I use utf8_encode($row[col]) everything's fine.

XistenZ
  • 309
  • 1
  • 4
  • 14

0 Answers0