Welcome Guest, Not a member yet? Register   Sign In
PHP stdClass object: getting data throught foreah loop
#1

[eluser]developer10[/eluser]
Basically, im pretty frustrated by the fact every time I have to hard-code my pagination whenever (and that is pretty much always) i want to use some filters (category, starting letter, etc) in my results before the final results are presented on the page.

The main problem here is that (IMHO) there is no easy (yet nice way) to get both number of records (that $config['total_rows'] will use) of that resultset (when filters apply) and have limited number of records per page, ready for pagination to render.

So, for a long time I'm struggling to find an acceptable way for me to use every time.
This is as far as I got.

My model:

Code:
function loadArtists($type, $letter, $uriOffset, $limit)
    {
        $query = "SELECT * FROM _tbl_artists WHERE ";
            if($type)
                $query .= "_artist_category = $type AND ";
            
            if($letter)
                $query .= "_ARTIST_NAME LIKE '$letter%' AND ";
        
        $query .= " id > 0 ORDER BY _ARTIST_NAME ASC ";
        
        if ($uriOffset)
            $limited = $query . " LIMIT $uriOffset, $limit";
        else
            $limited = $query;
        
        $noLimit = $this->db->query($query);
        $withLimit = $this->db->query($limited);
        
        $numRows = $noLimit->num_rows();
        $resultStack = array();
        $resultStack = array($numRows);
        
        
        if($withLimit->num_rows() > 0)
        {
            $result = $withLimit->result();
        }
        
        array_push($resultStack, $result);
        
        return $resultStack; //$resultStack;
    }

Now, when i send this resultset to my view (before that, in my controller i pull out the number of records needed by $config['total_rows ']), I can't figure out how to pull a piece of data i need to show on that page.

Here's the output of the above resultset:

Code:
Array
(
    [0] => 148
    [1] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 347
                    [_ARTIST_NAME] => EDIN CARIC
                    [_ARTIST_SEO_NAME] => edin-caric
                    [_artist_category] => 0
                    [_ID_ORIGINAL] => 3325
                )

            [1] => stdClass Object
                (
                    [id] => 348
                    [_ARTIST_NAME] => EDIN DENI OMEROVIC
                    [_ARTIST_SEO_NAME] => edin-deni-omerovic
                    [_artist_category] => 0
                    [_ID_ORIGINAL] => 3326
                )

            [2] => stdClass Object
                (
                    [id] => 349
                    [_ARTIST_NAME] => EDIN PASIC
                    [_ARTIST_SEO_NAME] => edin-pasic
                    [_artist_category] => 0
                    [_ID_ORIGINAL] => 3328
                )

            [3] => stdClass Object
                (
                    [id] => 3069
                    [_ARTIST_NAME] => EDIN UZUN EDY
                    [_ARTIST_SEO_NAME] => edin-uzun-edy
                    [_artist_category] => 0
                    [_ID_ORIGINAL] => 31693
                )

            [4] => stdClass Object
                (
                    [id] => 350
                    [_ARTIST_NAME] => EDIS I HARIS
                    [_ARTIST_SEO_NAME] => edis-i-haris
                    [_artist_category] => 0
                    [_ID_ORIGINAL] => 3330
                )

            [5] => stdClass Object
                (
                    [id] => 351
                    [_ARTIST_NAME] => EDISA
                    [_ARTIST_SEO_NAME] => edisa
                    [_artist_category] => 0
                    [_ID_ORIGINAL] => 3340
                )

        )
)

I'm totally unfamiliar with PHP stdClass and I have tried some options to convert it to array but to no avail.

OK, so what i need from the object is _ARTIST_NAME or other data from that level.

If anyone has any suggestions, please post!


Messages In This Thread
PHP stdClass object: getting data throught foreah loop - by El Forum - 06-26-2011, 11:49 AM
PHP stdClass object: getting data throught foreah loop - by El Forum - 06-26-2011, 12:58 PM
PHP stdClass object: getting data throught foreah loop - by El Forum - 06-29-2011, 11:15 AM
PHP stdClass object: getting data throught foreah loop - by El Forum - 06-29-2011, 11:23 AM
PHP stdClass object: getting data throught foreah loop - by El Forum - 06-29-2011, 12:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB