Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:46:40+00:00 2026-06-07T03:46:40+00:00

I’m creating a little php file to get mysql rows for my android application.

  • 0

I’m creating a little php file to get mysql rows for my android application.
to retrieve each single row i use:

    $q=mysql_query($sql, $this->conn) or die (mysql_error());
while($e=mysql_fetch_assoc($q)) {
      $output[]=$e;
    }
print(json_encode($output));

but sometimes it returns me an inconsistent output.

Here’s an example:
The row:

id=1 (correct) – name=”name1″ (correct) – price=200 (correct) – price2=null (correct) – area=null (NOT CORRECT) because area has a value of “Centro Città” .. and so on..

How can i resolve this problem?

EDIT: the value is

[{“id”:”84″,”idutente1″:null,”idutente2″:null,”idutente3″:null,”idutente4″:null,”idutente5″:null,”idagente”:null,”annuncio”:”0″,”archiviato”:”0″,”dataarchiviazione”:”2012-07-05 13:31:19″,”tipoimmobile”:”Residenziale”,”metodo”:”Vendita”,”area”:null,”presentazione”:”1″,”homepage”:”1″,”mappa”:”1″,”nome”:”Piazza Umberto I”,”luogo”:”Crotone”,”descrizione”:”60 mq composto da due vani oltre servizi, centralissimo buono per ufficio.”,”descdettagliata”:”
L’appartamento è diviso in due vani con cucina e bagno.</p>\r\nPosto nel pieno centro e vicinissimo al lungomare Regina Margherita.</p>\r\n Ottimo condominio. Libero e disponibile da subito. /p>”,”vani”:”2″,”prezzo”:”87000″,”prezzo1″:”0″,”prezzo2″:”0″,”prezzo3″:”0″,”prezzo4″:”0″,”prezzo5″:”0″,”metriquadri”:”58″,”stato”:”In buono stato”,”riscaldamento”:”Autonomo”,”classeenergetica”:”Non dotato”,”piano”:”Primo/secondo/terzo”,”indicazioni”:””,”mutuo”:”No”,”banca”:””,”importo”:””,”finalita”:””,”tipologia”:””,”ammortamento”:””,”visite”:”20″,”timestamp”:”2012-06-25 10:48:01″,”nomefile”:”HPIM2268.jpg”}]

area field is not null, but is “Centro Città”. The rest is correct.
I tried to show only the “area” field with a mysql_fetch_assoc($query) and it returns me the correct result: “Centro Città”. This problem is only with json_encode.

The SQL Variabile is:

$sql = sprintf("SELECT i.*, f.nomefile FROM immobili i LEFT JOIN foto f on(i.id=f.idimmobile AND f.copertina=1) WHERE i.id=%s", $_GET['id']);

This is only an example, if i ask other rows, the area field returns correctly also with json_encode and other fields return null. Could it be a problem related with the strings and the text format?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:46:41+00:00Added an answer on June 7, 2026 at 3:46 am

    It’s an encoding problem. json_encode() accepts only UTF-8 strings, and returns null if a string is not valid UTF-8.

    You can fix this by converting the encoding of your data before passing it to json_encode. Take a look at iconv() or mb_convert_encoding().

    For example, assuming your data is encoded in latin1:

    $e = array_map(function($string) {
        return iconv("iso-8859-1", "utf-8", $string);
    }, $e);
    
    $output[] = $e;
    

    Or if you have php < 5.3:

    function cb($string) {
        return iconv("iso-8859-1", "utf-8", $string);
    }
    
    $e = array_map('cb', $e);
    
    $output[] = $e;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.