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

  • SEARCH
  • Home
  • 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 8504733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:07:07+00:00 2026-06-11T02:07:07+00:00

I’m pretty sure I’m missing something simple, anyway, I have tried for the past

  • 0

I’m pretty sure I’m missing something simple, anyway, I have tried for the past three hours to JSON encode some query results, something I do it quite often with code igniter, however, it just doesn’t work, and I have no idea why.

I’m using CodeIgniter (latest version), PHP5.

My three files.

material_model MODEL

public function get_types(){
    return $this->db->query("SELECT * FROM material_types ORDER BY type_id")->result_array();
} // end function get_types

public function get_material($name){
    return $this->db->query("SELECT T.name as 'type', M.* FROM material M, material_types T WHERE T.type_id = M.type_id and T.name = '".$name."' ORDER BY M.type_id and M.order")->result_array();
} // end function get_material_all

material Controller

public function get_all(){
    $json['response'] = array('types' => array());
    $json['response']['types'] = $this->material_model->get_types();


    foreach ($json['response']['types'] as $item){
    $name = $item['name'];

    $json['response'][$name] = $this->material_model->get_material($name);          
    }

    $this->load->view('response', $json);
}

response VIEW

$this->output->set_status_header(200);
$this->output->set_header('Content-type: application/json');
echo json_encode($response);

The results -> http://goethedev.com/iib_ci/index.php/material/get_all/

What I use to validate the JSON pages -> http://jsonformatter.curiousconcept.com/

I’m displaying the whole results up there, I already tried to narrow it down for testing purposes to just row_array, only a couple of fields from table material_types, but no luck, this is also a new server I’m working on, that’s unlikely the problem, but I thought it was worth mentioning.

Thanks.

  • 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-11T02:07:08+00:00Added an answer on June 11, 2026 at 2:07 am

    The json being returned from the URL you provided is being displayed for me just fine, and it validates as well. Either you’ve fixed it since posting, or perhaps you need to clear your browser cache?

    UPDATE

    The code was validating just fine when I copy/pasted it to the validator you provided, but using the URL it fails. That tells me that there’s something extra/wrong that’s coming through that isn’t included when copy/pasting from the browser.

    To identify it I ran curl http://goethedev.com/iib_ci/index.php/material/get_all/ | less and here’s what I got:

    <U+FEFF><U+FEFF><U+FEFF>{"types":[{"type_id":"0","name":"DISCLAIMER","timestamp":"2012-09-08 22:57:27"},
    

    <U+FEFF> represents a byte order mark. Since there are three of them, it appears three files in your CI project have the byte order mark included. I recommend, as does PSR2, always disabling the byte order mark in your PHP code. Your editor should have an option to remove/disable them. Once you do that, you should be able to parse the json.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.