Jump to content

Oracle/PHP. NULL fields shifting my HTML table


mikesta707

Recommended Posts

Ok, this is a very confusing problem. So i built a class in PHP that takes the results of an oracle query, and puts them into an array, and I use another javascript class to create a table with the information.

 

So far, I have not run into a problem with this. However, I have with a recent query, I have come across a problem with null fields. When I preform the following code (simplified for ease of viewing):

 

while(OCIFetchInto($this->execute, $results, OCI_ASSOC)){
		if ($this->data == null){
			$this->data[] = $results;
			$this->columns = array_keys($results);
		}
		else {
			array_push($this->data, $results);
		}
                        if (count($results) > count($this->columns)){
			$this->columns = array_keys($results);
		}
	}

 

what seems to happen is that where ever there is a null field, the result array doesn't have certain keys that other result sets do. When building my table, everything gets screwy, because some result sets are longer than others, and some rows have less columns than the total amount of columns in the table, and some have more. Because of this, certain cells are not in the correct column.

 

Is there a way to make sure every array is the same length, and wherever there is a null value, instead of ignoring it, just adding a null value to the array under the correct key? I want to try to do this purely with PHP, because I have a lot of different queries that I need to do, and I don't want to have to change a query every time this problem may arise.

 

although I understand why the problem is happening, I honestly have no clue how to fix it, and I don't think I even explained the problem very well. Please, if you need more information, tell me. I can post the javascript stuff that builds the HTML, and the other class functions if needed, but i figured that any fix would go in building the array.

 

thanks in advance

 

 

Oh, here is an example of what I want to try to do, with simple data.

 

assuming that my query fetches the columns name, date, and awesome level, if my table had the following data

name    date   awesomeness
john    |  today | pretty awesome
Mike    | yesterday | null

 

instead of the result set being

arr[0] => array('name'=>'john', date=>'today', 'awesom'=>'pretty awesome')
arr[1] => array('name'='mike', date=>'today')

 

i want it to be

arr[0] => array('name'=>'john', date=>'today', 'awesom'=>'pretty awesome')
arr[1] => array('name'='mike', date=>'today', 'awesome'=>null)//or 'awesome=>""

 

 

 

 

Link to comment
Share on other sites

Alright, so I kind of figured out a way I might be able to do this.

 

With that PHP class, I get all the column names. What I may have to do is create a function that will take every single entry in the $this->data array (which is basically every row returned) go through it, and where an array key doesn't exist, insert it, and put an empty string into the value (Or the world Null, which ever) However, I am not sure how I would go about this. I am going to make an attempt, and I will get back to this post.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.