This topic is locked
[SOLVED]

  pull image and files from new json format?

7/14/2013 11:23:39 PM
PHPRunner General questions
W
wfcentral author

I searched the board and found some old code in the ASPrunner forum... but, it did not work.
I have two tables (properties and documents).
PROPERTIES TABLE - FIELD "icon"
[{"name":"files\/icon-angelfire_rirtanh2.png","usrName":"icon-angelfire.png","size":1359,"type":"image\/png","thumbnail":"files\/thicon-angelfire_4sjavl61.png","thumbnail_type":"image\/png","thumbnail_size":1359,"searchStr":"icon-angelfire.png,!:sStrEnd"}]
DOCUMENTS TABLE - FIELD "documents"
[{"name":"files\/Covey Call Count Data Sheet_9yj21k6l.pdf","usrName":"Covey Call Count Data Sheet.pdf","size":63090,"type":"application\/octet-stream","searchStr":"Covey Call Count Data Sheet.pdf,!Bird Sampling for Research Lab.docx,!Fall Covey Counts.pdf,!Helicopter Counting for Quail.pdf,!:sStrEnd"},{"name":"files\/Bird Sampling for Research Lab_d0enyee2.docx","usrName":"Bird Sampling for Research Lab.docx","size":15769,"type":"application\/vnd.openxmlformats-officedocument.wordprocessingml.document"},{"name":"files\/Fall Covey Counts_hdhtb5s7.pdf","usrName":"Fall Covey Counts.pdf","size":69069,"type":"application\/octet-stream"},{"name":"files\/Helicopter Counting for Quail_lhedhm4c.pdf","usrName":"Helicopter Counting for Quail.pdf","size":2006470,"type":"application\/octet-stream"}]
This is how PHPrunner stores the data in the fields (see above).
I'm trying to do two things.
On my website I want to pull the image (field "icon") of the property.
[icon] lorem ipsum
On my website I want to have a page called "document library" and I want to pull the documents. So, on that page it would look like this...
Research Papers by Robert

  • thisfile.doc
  • thatfile.pdf
  • anotherfile.xls
    (see in this second scenario there are multiple files uploaded to the field "documents")
    I'm at a loss...

Sergey Kornilov admin 7/15/2013

PHPRunner manual is usually a good place to start:

http://xlinesoft.com/phprunner/docs/rename_uploaded_file.htm

W
wfcentral author 7/15/2013

I'm going to reply to my own post because I found the answer and maybe someone else can use it.
The help files mentioned in the previous post will show you how to do things INSIDE phprunner and maybe you can figure out how to modify that to do what you need. For me, it didn't make a lot of sense so I went digging. Here is what I found.
Data stored in a field that looks like this
[{"name":"files\/icon-angelfire_rirtanh2.png","usrName":"icon-angelfire.png","size":1359,"type":"image\/png","thumbnail":"files\/thicon-angelfire_4sjavl61.png","thumbnail_type":"image\/png","thumbnail_size":1359,"searchStr":"icon-angelfire.png,!:sStrEnd"}]
is JSON format. The square brackets on the end tell you that it is an ARRAY (meaning it contains more then one piece of data...)
A JSON format that is NOT an array might look like this...

{"name":"files\/icon-angelfire_rirtanh2.png"}
I was creating a mobile webpage and I just wanted to pull some images from a field in the database maintained by phprunner. I have the phprunner mobile template, but I'm looking for something built in mobile jquery and more user friendly + prettier for public use.
My image is stored in a field called "icon" and looks like this...

[{"name":"files\/icon-angelfire_rirtanh2.png","usrName":"icon-angelfire.png","size":1359,"type":"image\/png","thumbnail":"files\/thicon-angelfire_4sjavl61.png","thumbnail_type":"image\/png","thumbnail_size":1359,"searchStr":"icon-angelfire.png,!:sStrEnd"}]
So, the only thing I need to pull out of here is the value for "name"
Here is the code I'm using in my database call on my mobile page
$icon = $rows['icon'];

$myArray = json_decode($icon, true);

$myIcon = $myArray[0]['name']; // Fetches the first ID
Later, I'm going to use this same process to pull multiple files from a document library.
So, I can do this...
$document = $rows['filename'];

$myArray = json_decode($document , true);

$myFile = $myArray[0]['filename']; // Fetches the first filename

$myFile = $myArray[1]['filename']; // Fetches the 2nd filename

$myFile = $myArray[2]['filename']; // Fetches the 3rd filename

$myFile = $myArray[3]['filename']; // Fetches the 4th filename
and if I find time to research or play with it more I might modify it so it will loop as long as it keeps finding files...