Giter VIP home page Giter VIP logo

Comments (6)

andrewscofield avatar andrewscofield commented on August 9, 2024

Hey, did you figure this out? It would be great for future reference to post an answer/example of how to handle results from Parse.com

from parse.com-php-library.

FredvanRijswijk avatar FredvanRijswijk commented on August 9, 2024

Yes, I'll be make a blogpost or something... but also for documentation in the wiki here... Building some real life examples.


        $parseQuery = new parseQuery('Locations');
        $results = $parseQuery->find();

        echo '
        <table class="table table-hover">
        <thead>
         <tr>
            <th>Name</th>
            <th>Address</th>
            <th>Published</th>
         </tr>
        </thead>
        <tbody>
        ';

        foreach( $results->{'results'} as $obj )
        {
            echo '<tr>
                    <td>' .$obj->{'name'}. '</td>
                    <td>' .$obj->{'address'}. '</td>
                    <td>' .$obj->{'published'}. '</td>
                  </tr>';
        }   

        echo '

        </tbody>
        </table>';
        ?>

Dirty, but it's working for now.

from parse.com-php-library.

liorwn avatar liorwn commented on August 9, 2024

It's probably not the best way to do it, but I find it comfortable for my purposes.

I added this function to class which converts objects to arrays (the response you get from Parse is an stdClass object):

function object_to_array($var) {
$result = array();
$references = array();
foreach ($var as $key => $value) {
// recursively convert objects
if (is_object($value) || is_array($value)) {
// but prevent cycles
if (!in_array($value, $references)) {
$result[$key] = object_to_array($value);
$references[] = $value;
}
} else {
// simple values are untouched
$result[$key] = $value;
}
}
return $result;
}

And then, following the example you started with, I do this:

$responseArray = object_to_array($response3);

And then I just foreach through the responses like so:

foreach($responseArray['results'] as $val)
{

echo $val['STREET'];

}

Let's say you have a column in your 'Locations' table like you mentioned in the example that is named 'STREET' then you can access that specific record like above.

Hope this helps a bit!

I should mention that I need an array for my uses, you can just as well foreach the original object itself.

from parse.com-php-library.

andrewscofield avatar andrewscofield commented on August 9, 2024

Thanks guys... any example are much needed! I will try to spend some time soon to develop docs for this repo but any help is great.

I should note too that according to this:

http://stackoverflow.com/questions/4345554/convert-php-object-to-associative-array

you might not need that object_to_array function at all. In the case of parse responses, they are simple enough to just typecast them and it will convert them.

from parse.com-php-library.

liorwn avatar liorwn commented on August 9, 2024

Oh man - that's great! Should've thought of that

On Mon, Oct 22, 2012 at 10:55 AM, apotropaic [email protected]:

Thanks guys... any example are much needed! I will try to spend some time
soon to develop docs for this repo but any help is great.

I should note too that according to this:

http://stackoverflow.com/questions/4345554/convert-php-object-to-associative-array

you might not need that object_to_array function at all. In the case of
parse responses, they are simple enough to just typecast them and it will
convert them.


Reply to this email directly or view it on GitHubhttps://github.com//issues/52#issuecomment-9666749.

from parse.com-php-library.

andrewscofield avatar andrewscofield commented on August 9, 2024

I think a lot of people have the same reaction when they first see this answer... I know I did!

from parse.com-php-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.