Reputation: 107
i just want to know how to do that think, probably is easy but atm i can't find the way to do it.
I have this code:
$results = $resultado->getRecords();
foreach ( $results as $result ){
// do something here
}
And i need to store every record in a json array. Why i need to do that? Becouse in the html page I show the last record, but I have a button which have to go back to the array of records, from last (100) to the first (1). So, i think the best way to do it is to create a jSON array with an index of numbers, and then everytime I click the button, i acces to the correct number and show that record.
EDIT: When i do that :
$results = $resultado->getRecords();
$json_data = json_encode($results);
my json_data returs this:
[{"_impl":{"_fields":{"Fecha Alta":["19\/03\/1994"],"Codigo":["test"],"Nombre":["test"],"Idioma":["test"],"Division":["test"],"Division 2":["test"],"Marca":["test"],"Empresa":["test"],"Stock":["test"],"Precio Unitario":["test"],"Urlpdf":["test.pdf"],"id":["4009"],"Vigente Desde":["test"]},"V5e7ec2d5":[],"_recordId":"4009","_modificationId":"2","_layout":{"_impl":{"_fm":{"V73ee434e":{"charset":"UTF-8","locale":"en","logLevel":3,"hostspec":"null","recordClass":"null","prevalidate":false,"database":"null","username":"null","password":"null"},"Vea4b3413":null,"V9a3dcbce":null},"_name":"null","_fields":{"Fecha Alta":{"_impl":{"_layout":null,"_name":"Fecha Alta","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"text","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"Codigo":{"_impl":{"_layout":null,"_name":"Codigo","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"number","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"Nombre":{"_impl":{"_layout":null,"_name":"Nombre","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"text","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"Idioma":{"_impl":{"_layout":null,"_name":"Idioma","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"text","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"Division":{"_impl":{"_layout":null,"_name":"Division","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"text","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"Division 2":{"_impl":{"_layout":null,"_name":"Division 2","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"text","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"Marca":{"_impl":{"_layout":null,"_name":"Marca","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"text","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"Empresa":{"_impl":{"_layout":null,"_name":"Empresa","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"text","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"Stock":{"_impl":{"_layout":null,"_name":"Stock","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"text","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"Precio Unitario":{"_impl":{"_layout":null,"_name":"Precio Unitario","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"number","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"Urlpdf":{"_impl":{"_layout":null,"_name":"Urlpdf","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"text","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"id":{"_impl":{"_layout":null,"_name":"id","_autoEntered":true,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"text","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}},"Vigente Desde":{"_impl":{"_layout":null,"_name":"Vigente Desde","_autoEntered":false,"_global":false,"_maxRepeat":1,"_validationMask":0,"_validationRules":[],"_result":"text","_type":"normal","_valueList":null,"_styleType":null,"_maxCharacters":0}}},"_relatedSets":[],"_valueLists":[],"Vab234ad8":[],"_database":"null","_extended":false}},"_fm":{"V73ee434e":{"charset":"UTF-8","locale":"en","logLevel":3,"hostspec":"null","recordClass":"FileMaker_Record","prevalidate":false,"database":"null","username":"null","password":"null"},"Vea4b3413":null,"V9a3dcbce":null},"_relatedSets":[],"_parent":null}}]
Tbh i don't know why filemaker gives me that fields. I only need the first ones :
{"Fecha Alta":["19\/03\/1994"],"Codigo":["test"],"Nombre":["test"],"Idioma":["test"],"Division":["test"],"Division 2":["test"],"Marca":["test"],"Empresa":["test"],"Stock":["test"],"Precio Unitario":["test"],"Urlpdf":["test.pdf"],"id":["4009"],"Vigente Desde":["test"]}
So, i only need what is in _fields {} .
How i should do it?
Thank you all guys!
Upvotes: 0
Views: 62
Reputation: 3437
Try this
$resultSet = array();
$results = $resultado->getRecords();
foreach ( $results as $result ){
// Do your operation over $result
$resultSet[] = result;
}
$json_data = json_encode($resultSet);
Upvotes: 0
Reputation: 45500
No need to loop, try this:
$results = $resultado->getRecords();
$json_data = json_encode($results);
Upvotes: 2