简体   繁体   中英

data array is dropped if the column is null or empty in Database

My table contains columns with null values. But when I try to retrieve the data set in to a variable,data array is dropped if the column is null or empty.

lets say as I have 4 columns

[cid] => 357
[smcoordinator] => 
[title] => Null
[cname] => Maddox Adam  Portland

And my function is,

function getValue($data){

      $dataset = $data['dataset']['result_set'];
      print_r($dataset);

      //somecode...
}

resut in the print_r

[cid] => 357
[smcoordinator] => 
[cname] => Maddox Adam  Portland

How can I get the Null column to my dataset?

Try replacing NULL with something else

$dataset = $data['dataset']['result_set'];
$Title = $dataset['title'];

//if title has no value give it one 
if (!$Title)
{
  $Title = "No Value";
}

then rebuild your result set array

$data['dataset']['result_set']['title'] = $Title;

Let me know if it works!

Severity: Notice

Message: Undefined index: title

Filename: helpers/cigen_helper.php

Line Number: 42

– user2006282 3 mins ago

Ok in MYSQL itself check that the title column is not a key column or index column as these columns cannot be null and make sure NOT NULL is not ticked

And that SQL error tells you its looking for an Index

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM