phpmysqlsqljoomlajoomla3.3

Choosing specific sql data within curly braces


I apologize in advance for my limited understanding of the terminology used.

What I'm trying to do is call data from a specific row and column, I've narrowed down my query that far - the issue I'm having is choosing the proper data inside is inside curly braces separated by commas. I've uploaded a screenshot.

https://i.sstatic.net/CCSGV.jpg

This is my php query ($catId is a value for the current category which is working correctly.)

<?php $db = JFactory::getDBO(); ?>
<?php $db->setQuery("SELECT params FROM #__categories WHERE id = '".$catId."'"); ?>
<?php $catimg = $db->loadResult(''); ?>
<?php echo $catimg; ?>

The echo is just to see if its pulling the right data and this is what its showing:

{"category_layout":"","image":"images/banners/white.png","color":"#000000"}

The data I'm trying to get is from "image", then echo it into an image tag -but this is where I'm stumped.

Any help would be greatly appreciated. Thank you.


Solution

  • If i understood you would like something like:

    <?php
    $db->setQuery("SELECT params FROM #__categories WHERE id = '".$catId."'");
    $catinfo = json_decode($db->loadResult(''), true);
    $catimg = $catinfo['image'];
    echo $catimg;
    ?>
    

    The info in the curly braces is in the JSON format which could be simply parsed with php built-in function json_decode(jsonString)