Home > php > php json_encode returns blank for array

php json_encode returns blank for array

December 2Hits:4

I am trying to return the result of a mysql query as json, but the json_encode function always returns a blank although the array contains elements.

Here is the relevant code

Retrieve the query and convert to php array:

$sql = "blablabla"; $clients = mysql_query($sql, $con);  $result = array(); while($row = mysql_fetch_assoc($clients)) {     //echo "rij: " . $row['name'];     $result[] = $row; } 

Then I return the result:

echo json_encode($result); 

This returns nothing, while I do get results when echoing the following statements:

echo count($return); 

returns 1

echo $return[0]; 

returns "Array"

echo $return[0]['name']; 

returns "Robert"

Any idea what I am doing wrong?

Tags:php, mysql, arrays, json

Related Articles

  • php json_encode returns blank for arrayDecember 2

    I am trying to return the result of a mysql query as json, but the json_encode function always returns a blank although the array contains elements. Here is the relevant code Retrieve the query and convert to php array: $sql = "blablabla"; $clie

  • Returning a 2D array from a PHP soapserver in c# come in blank.February 15

    I created a PHP soapServer and am connecting the service to C#. I've got most of the methods to work correctly but am having trouble when it comes to my SelectUser method which returns a 2d array of strings. When I pull the data it prints out blank.

  • wp_handle_upload returns empty error arrayAugust 27

    I am trying to do an upload via ajax and really dont want to use the regular wordpress media uploader. It is too much stuff and all i want to do is upload single image. I have everything working the ajax is sending the uploaded file via this Jquery p

  • Why does field_get_items() sometimes return "blank"April 23

    field_get_items('node', $my_node_object, 'field_[fieldname]') is returning the string 'blank'. Not an array, not NULL, but a string reading 'blank'. It's causing errors in media_wysiwyg module. What causes this? How can I fix it? --------------Soluti

  • Why json_encode returns empty brackets?January 24

    var_dump of $array returns this : array (size=3) 0 => object(frontend\models\Notifications)[101] private '_attributes' (yii\db\BaseActiveRecord) => array (size=5) 'id' => int 1 'created_on' => string '2015-11-12 12:12:15' (length=19) 'user_id'

  • Android- Metaio AR onGeometry Touch returning blank name for particular geometryFebruary 1

    I am using Metaio sdk for AR in android. I am creating an array of POI's in which am setting name for each geometry.My problem is that in onGeometryTouched method i am trying to use method geometry.getName() but it is returning blank. Please find my

  • IIS7 returns blank when static content requested

    IIS7 returns blank when static content requestedAugust 12

    I am trying to configure a demo machine which is EEEPC with Windows 7 Home Premium edition all the drivers properly loaded (don't ask me why it's Home edition) with IIS7 installed. I've deploy the application to be demo-ed on the machine which is an

  • shortcode causing the_content() to return blank?November 7

    I have a shortcode that just retrieves some info from the options table in the database. For whatever reason, when the content reaches a certain character limit the_content() to return blank? The function is pretty basic and I can't for the life me f

  • Site Configuration returns blank pageJuly 16

    I have just updated the Internationalization and language_dropdown modules successfully after Drupal asked me to. Having done that, the site configuration when clicked every time, returns blank page. Sometimes when I click it twice, it returns a scre

  • WMSGetFeatureInfo returns blankMay 22

    I've been working on a WMS with a QuantumGIS server. So I've added the QGIS map as a layer to my OpenLayers map on my webpage. Now I want to use the WMSGetFeatureInfo function of OpenLayers to get information about the feature I've been clicking on.

  • get_the_categories filter returns an empty arrayJuly 27

    I'm developing a theme that uses the get_the_category_list() function (in category-template.php). Examining its code, this function calls the get_the_category() function (in category-template.php) which applies the get_the_categories filter at the en

  • wp_get_nav_menu_items() returns an empty array under tags archiveSeptember 11

    I have three nav menus and for some reason under tags archive wp_get_nav_menu_items('MenuName') returns an empty array. Frontpage, posts, pages are OK, but when you go into tags archive, no items are returned. Here is my code in functions.php: functi

  • return paginate_comments_links() as arrayDecember 4

    The documentation specifies: type (string) (optional) Controls format of the returned value. Possible values are: 'plain' - A string with the links separated by a newline character. 'array' - An array of the paginated link list to offer full control

  • Which Java string value is preferred to return: blank or null?February 21

    I came across this snippet and am wondering if I should return blank in this case. Which is more practical to return: blank or null? public String getInfo() { String result = ""; String uri = clientConfiguration.getUri(); String regex = "ht

  • getCameraIdList() function returns an empty arrayMay 12

    I'm trying to work with Android's camera API 2, and I had a bug which I wasn't able to fix. The function getCameraIdList() returns an empty array for some reason, although I do have 2 working cameras on my emulator (I checked it using the Android cam

  • ArcGIS Server 10.2.2 - Map Export Sometimes Returns Blank ImageJanuary 24

    I've run into a fun little issue with ArcGIS Server 10.2.2 to end my week with... I have discovered today that the export operation (the one that renders map layer images) is randomly returning blank images. As in - I enter a export url into the brow

  • Android package manager (pm) returns blank on every commandMay 19

    For example if I run the command pm list packages, pm list permission-groups, pm uninstall com.google.android.apps.books, etc. All return blank and seem to have done nothing. I do have root, I'm using Terminal Emulator which is a reputable emulator,

  • PHP returning blank pagesJuly 23

    So everything was working fine after I changed some permissions of a folder inside /var/www/html. It was just a random project. IIRC I just did chmod u+x, that's it. This created the whole mess, I suppose, i.e. when I open the PHP files now, they are

  • PyQGIS export return blank .tifSeptember 29

    I'm new to pyqgis and trying to bring up from the previous post with a little progress from the last (implemented debugging tool pdb) but now trying to export into a .tif file so that I can check on the vertices from the csv geometry. Unfortunately I

  • Social media data returns blank outputNovember 28

    I have mathematica 10.3 The SocialMediaData command, asks me for for an access key. When I paste it, it returns a blank network. The related commands also return blank lists ``{}''. I work on linux (ubuntu and archlinux with both awesome and gnome en

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.545 s.