Forums

DB Data retrieval problem CCV5

paulzero 06 Aug, 2016
Hi !

Got a small DB data retrieval problem : Trying to get a plugins xml parameter data from a table field for editing in frontend. Data is stored in that table field in the format :

{"value1":"today","value2":"yesterday","debug":"0"}

When attempting to retrieve that data CCV5 returns nothing (Other data in same table fields returned OK).

Copied data without brackets to another field in same table & CCV5 returned data OK.

So it appears CCV% wont allow import of bracketed data. Is there a way around this ? Some way to strip brackets out, load & edit data, add brackets & save ? Or is there a function in CCV5 to allow the importing & editing of XML files ?

Cheers PaulZero.
GreyHead 13 Aug, 2016
Hi PaulZero,

Sorry for the delay - I had to experiment with this. I got it to work OK using the PHP Functions box on the Front List > Settings tab. Here's the code I used (testing with the content of the 'images' column in the #__content table.
content.images:$temp = json_decode($cell); if ( empty($temp->image_intro) ) { return 'empty'; } else { return  $temp->image_intro; } 

Note: there was no problem in loading the JSON encoded string so what this does is to de-code it and pull out one value for display.

Bob
paulzero 15 Aug, 2016
Hi Bob !

Thanks for your reply - I get the idea but i'm not that good with syntax so can you please advise based on the following
If  'Model name' = 'MyImages'

And 'Table Name' = 'abcd_content'

And 'Conditions' = <?php return array ("MyImages.id = 1"); ?>

And 'Frontlist' > 'Columns list' = 'MyImage.image_intro:Image Intro text'

And 'Frontlist' > 'Edit linkable" = 'MyImage.image_intro'


Would 'Frontlist' > 'PHP' syntax be :
MyImages.images:return<?php
content.images:$temp = json_decode($cell); if ( empty($temp->image_intro) ) { return 'empty'; } else { return  $temp->image_intro; } ?>


And having got that value, how would I write a new value back to that DB cell ? Currently I have an 'Edit' action that adds the value of 'image_intro' to a string then 'saves' that string using the 'name' value in 'button > submit', eg :

Frontlist > Actions > Edit > Code :
New Image-Intro :<input type="text" name="[MyImage.image_intro]"
<input type="hidden" name="{"image_intro":"[MyImage.image_intro]","float_intro":""}" /><br>
<input class="button" type="submit" value="Save" /><br>

Thanks for your excellent assistance,

PaulZero
GreyHead 15 Aug, 2016
Hi PaulZero,

The condition is missing a > and seems to have some extra quotes??
<?php return array ( "MyImages.id" => 1 ); ?>


You have added what looks like some unnecessary code on the start and end of what you have called the FrontList PHP syntax (where do you have that?).

I have no idea what the code in the Edit action does - I can't make any sense of it :-(

Bob
paulzero 15 Aug, 2016
Hi Bob,

Thanks for your advice. I will fix 'condition' as per your post.
I can see that once your code snippet was inserted into Frontlist > Settings Tab > PHP Functions it would create a variable called $temp, I just can figure out how to pull the value of $temp into a form then edit it & save it.
I not at all sure of how one associates a $value with an model.field in CCV5 for editing.
Further, once I have edited the value of $temp in a form I have no idea of how to save the result back to the db field.
Could you please advise the best approach - for example, is there a way to just 'save' that value back into the string from which it was extracted or do I have to create a new, compete, punctuated sting which includes the value of $temp (plus the strings other fixed value pairs) and write the whole string back to the db field ? Any example would be greatly appreciated.
Thanks for your assistance,
Cheers PaulZero.
GreyHead 15 Aug, 2016
Hi PaulZero,

I have no idea either. This will let you display the value in a CC Listing. If you want to use and save the value in a CF form then I suggest that you look up the value in a Custom Code action in the form. Using a normal 'Edit' link should let you do that.

Bob
paulzero 16 Aug, 2016
Hi Bob,
Thanks for your help with this. I've decided to forget it for now - have read up all the json encode - decode php info, can see how it could be done using custom code in CCV5 but beyond my skills at this time.
I'll make that another large coffee !
Cheers PaulZero.
GreyHead 16 Aug, 2016
Hi PaulZero,

The JSON encode/decode just converts JSON strings - like the example you posted - to and from an array (or an object). It's a way of converting multi-dimensional data into a plain string that is easier to transmit or store. The latest version of MySQL has some JSON functionality built in - but I don't have it installed to test yet.

Bob
This topic is locked and no more replies can be posted.