W
william_teale author
I am having real trouble decoding the json content of a field in my database. I used phprunner 10.3 to create a page where multiple images can be uploaded at the same time, the info being stored in a text field. Everything seems to work perfectly (images upload, text stored in field properly) until I try to decode it using php on the web page. The code I am using is as follows...
<?php $someArray = json_decode($Recordset1->getColumnVal("OTHER_IMAGES"), true); foreach ($someArray as $key => $value) {
echo "<div class=\"col-md-4\" style=\"margin-bottom: 5px\" ><a href=\"" . $value["name"] . "\" class=\"fancybox img-hover-v2\"><span><img src=\"" . $value["thumbnail"] . "\" class=\"img-fluid\"></span></a> </div>";
}
?>
When I run the same code, with the content of the field entered into the code, it works just as intended.
<?php $fulljson = '[{"name":"..\/vendor_images\/01_3fzd5wkh.png","usrName":"01.png","size":118406,"type":"image\/png","thumbnail":"..\/vendor_images\/th01_u5f3fl6s.png","thumbnail_type":"image\/png","thumbnail_size":118406,"searchStr":"01.png,!02.png,!03.png,!:sStrEnd"},{"name":"..\/vendor_images\/02_5tkaoqv1.png","usrName":"02.png","size":125586,"type":"image\/png","thumbnail":"..\/vendor_images\/th02_jjj5ro58.png","thumbnail_type":"image\/png","thumbnail_size":125586},{"name":"..\/vendor_images\/03_bp34jgek.png","usrName":"03.png","size":108485,"type":"image\/png","thumbnail":"..\/vendor_images\/th03_cp7ofn1w.png","thumbnail_type":"image\/png","thumbnail_size":108485}]'; $someArray = json_decode($fulljson, true); foreach ($someArray as $key => $value) {
echo "<div class=\"col-md-4\" style=\"margin-bottom: 5px\" ><a href=\"" . $value["name"] . "\" class=\"fancybox img-hover-v2\"><span><img src=\"" . $value["thumbnail"] . "\" class=\"img-fluid\"></span></a> </div>";
}
?>
When I run the php var_export() I get the full text I expected in the field
'[{"name":"..\/vendor_images\/01_3fzd5wkh.png","usrName":"01.png","size":118406,"type":"image\/png","thumbnail":"..\/vendor_images\/th01_u5f3fl6s.png","thumbnail_type":"image\/png","thumbnail_size":118406,"searchStr":"01.png,!02.png,!03.png,!:sStrEnd"},{"name":"..\/vendor_images\/02_5tkaoqv1.png","usrName":"02.png","size":125586,"type":"image\/png","thumbnail":"..\/vendor_images\/th02_jjj5ro58.png","thumbnail_type":"image\/png","thumbnail_size":125586},{"name":"..\/vendor_images\/03_bp34jgek.png","usrName":"03.png","size":108485,"type":"image\/png","thumbnail":"..\/vendor_images\/th03_cp7ofn1w.png","thumbnail_type":"image\/png","thumbnail_size":108485}]'
There are no errors in the console. A link to the output mentioned can be seen here Can anybody see what I have done wrong, or offer another method for decoding the json?
|
|