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 6474819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:37:57+00:00 2026-05-25T06:37:57+00:00

I insert data with json_encode() in database, now i want get( select * from

  • 0

I insert data with json_encode() in database, now i want get(select * from <table> ...) only name_unitsin of database? i want output this-> salam & mokhles & fadat

In database row units:

[{"name_units":"salam","price_units":"74,554","checkbox_units":["minibar","mobleman"]},
 {"name_units":"mokhles","price_units":"4,851,269","checkbox_units":["mobleman","tv"]},
 {"name_units":"fadat","price_units":"85,642","checkbox_units":["minibar","mobleman","tv"]}]

.

$query_hotel_search = $this->db->query("SELECT * FROM hotel_submits WHERE name LIKE '%$hotel_search%' ORDER BY name asc");
$data = array();
foreach ($query_hotel_search->result() as $row)
{
   $units = json_decode($row->units);
   $data[] = array('name' => $row->name, 'units' =>$units['name_units']); // Line 24
}
echo json_encode($data);

This is output above code:

A PHP Error was encountered
Severity:
Notice
Message: Undefined index: name_units
Line Number:
24

[{“name”:”Jack”,”units”:null}]

  • 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-05-25T06:37:57+00:00Added an answer on May 25, 2026 at 6:37 am

    You’re getting an array of stdClass objects as a result from json_decode, rather than an associative array as you’d expect. It looks like you’ve got an array of JSON strings located in the same cell of your DB.

    Assuming that’s how your DB table is structure, if you want to output

    salam & mokhles & fadat

    then try this:

    foreach( $query_hotel_search->result() as $row ) {
        $units = json_decode( $row->units );
        $names = '';
        foreach( $units as $unit ) {
            $names .= "{$unit->name_units} & ";
        }
    }
    echo substr( $names, 0, -2 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get data from my Sqlite database and put it into this
I insert data with json_encode() in database, want get just values name_units on row
I want to be able to insert data from a table with an identity
I insert several( array ) value with json_encode in one row from database table,
How i can insert data into more than one table of an Access database
I want to insert data into a table where I don't know the next
I have table that I insert data with following query (from c# code): INSERT
I want to load data from a MySQL database to a PHP page using
I'm trying to insert information from a form into a database table and then
I inserted on a row of database table values, now I want echo them

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.