я просто хочу знать, как это сделать, думаю, это легко, но я не могу найти способ сделать это.
У меня есть этот код:
$results = $resultado->getRecords();
foreach ( $results as $result ){
// do something here
}
И мне нужно хранить каждую запись в массиве JSON. Почему я должен это сделать? На странице html я показываю последнюю запись, но у меня есть кнопка, которая должна вернуться к массиву записей, от последней (100) до первой (1).
Итак, я думаю, что лучший способ сделать это — создать массив jSON с индексом чисел, а затем каждый раз, когда я нажимаю кнопку, я получаю доступ к правильному номеру и показываю эту запись.
РЕДАКТИРОВАТЬ:
Когда я это делаю:
$results = $resultado->getRecords();
$json_data = json_encode($results);
мои json_data возвращают это:
[{"_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}}]
Я не знаю, почему FileMaker дает мне эти поля. Мне нужны только первые:
{"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"]}
Итак, мне нужно только то, что находится в _fields {}.
Как мне это сделать?
Спасибо всем ребята!
Не нужно зацикливаться, попробуйте это:
$results = $resultado->getRecords();
$json_data = json_encode($results);
Попробуй это
$resultSet = array();
$results = $resultado->getRecords();
foreach ( $results as $result ){
// Do your operation over $result
$resultSet[] = result;
}
$json_data = json_encode($resultSet);