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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:39:12+00:00 2026-06-07T19:39:12+00:00

To give some context, a little while ago with the help from VolkerK on

  • 0

To give some context, a little while ago with the help from VolkerK on this very site I created a function that queries an Oracle database and places the content into a neatly formatted PHP array, depending on the index. Here’s the original question.

The problem is, in some cases I just want to return a single value from a quick query, and when I do I get the the following error: Notice: Undefined index:

Here’s the code I’m using:

function oracleGetData($query, $id = null) {
    global $conn;

    $results = array();
    $sql = OCI_Parse($conn, $query);
    OCI_Execute($sql);
    while ( false!==($row=oci_fetch_assoc($sql)) ) {
        $results[ $row[$id] ] = $row;
    }

    // remove one layer if there's only one record
    if(count($results) == 1 and is_null($id)) {
        $results = array_pop($results);
    }
    return $results;
}

I have tried changing the line that populates the array like so:

if(is_null($id)) {
    while ( false!==($row=oci_fetch_assoc($sql)) ) {
        $results[ $row ] = $row;
    }
} else {
    while ( false!==($row=oci_fetch_assoc($sql)) ) {
        $results[ $row[$id] ] = $row;
    }
}

Basically if the $id variable is null, remove all references to it, but then I get a ‘Warning: Illegal offset type’ error.

Any help would be much appreciated, I’ve tried passing in the single field I require into the function but get the same error.

Thank you

  • 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-07T19:39:13+00:00Added an answer on June 7, 2026 at 7:39 pm

    Perhaps if $id is NULL you could just use sequential numbers for the indexes, as in:

    function oracleGetData($query, $id = null)
      { 
      global $conn; 
    
      $results = array(); 
      $sql = OCI_Parse($conn, $query); 
      OCI_Execute($sql); 
    
      if(is_null($id)) {
        $idx = 1;
    
        while (false!==($row=oci_fetch_assoc($sql))) { 
          $results[ $idx ] = $row;
          $idx = $idx + 1;
        }
      } else { 
        while ( false!==($row=oci_fetch_assoc($sql))) { 
          $results[ $row[$id] ] = $row;
        }
      } 
    
      // remove one layer if there's only one record 
    
      if(count($results) == 1 and is_null($id)) { 
        $results = array_pop($results); 
      } 
    
      return $results; 
      } 
    

    Share and enjoy.

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

Sidebar

Related Questions

Could anyone give me some help with this please? The content needs to appear
Good people - Need a little help. I am making a site that will
To give some context, the following dropdown is within a form that gives the
To first give a little bit of context, my use-case is that my partner
Anybody please give some useful links on this topic.i need to create a content
I've been give some lovely Java code that has a lot of things like
I've created a bunch of projects in Eclipse 3.7.2. Let's give some of them
Can some give me good jQuery lightbox plugin which has zoomin and zoomout function
Just to give a little more context to the question, I have a web
Guys i need some help here , im getting this error here at the

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.