1

I'm using the "phpsoda" library and trying to query the city of Seattle's permits dataset through the Socrata API (SODA). Data: https://data.seattle.gov/Permitting/Land-Use-Permits/ht3q-kdvx

They have several columns such as the ones I'm selecting below, but in the "AppliedDate" and "IssuedDatae" columns, there may or may not be data in that column.

So when I try to look at the array and arrange this into an HTML table, I'm getting some arrays (rows) that have fewer elements (columns) than other rows. This turns out to make it difficult to display since I don't know which columns are missing in the array (row).

I'm wondering if when I make the query, that those empty fields will look they seem in the visualized table on their site or when I export a CSV. Those columns in the query will return into the array element an empty string ("") instead so my rows and columns will come out all filled with values.

$soql->select("PermitNum", "AppliedDate", "IssuedDate", "Description", "OriginalAddress1")
     ->where("PermitClass = 'Multifamily' OR PermitClass = 'Commercial')
     ->limit(20);

$results = $ds->getDataset($soql);

Data would look something like...

print_r($results);

Array[0] -> [Description]=>"XXXXXXX", [PermitNum]=>"123456"
Array[1] -> [Description]=>"XXXXXXX", [PermitNum]=>"234567", [AppliedDate]=>"XX/XX/XXXX"

So the first row is missing the "AppliedDate" column just because it's not in the data.

Will I need to just go through this manually in the results array using a loop and checking column names and inserting an empty string if the loop doesn't find a column?

AS Mackay
  • 2,831
  • 9
  • 19
  • 25
alin
  • 11
  • 2

2 Answers2

0

Following my own advice, I was able to just check for each row key if a specific key was missing (array_key_exists function), then I'd fill it in with "" if it returned false.

This seemed to work.

alin
  • 11
  • 2
0

I have same problem. Socrata API will skip empty field or null value. Means, if field is null or empty, the result will not show field-name:'', instead, the result will just missing this, that cause your shorter row.

This is annoying bug, I have to fix it by my own. If I found it missing field, I will have to add field-name:'' to the result json, that will fix your shorter row problem. Make equal length row.

hoogw
  • 4,982
  • 1
  • 37
  • 33