mikesta707 Posted September 29, 2009 Share Posted September 29, 2009 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=>"" Quote Link to comment https://forums.phpfreaks.com/topic/175985-oraclephp-null-fields-shifting-my-html-table/ Share on other sites More sharing options...
mikesta707 Posted September 29, 2009 Author Share Posted September 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/175985-oraclephp-null-fields-shifting-my-html-table/#findComment-927314 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.