Wednesday, 2 August 2017

if statement - IF/ELSE to echo image in PHP

I think this is what you're wanting...


    for ($tmp = 0; $tmp < 10 && $tmp < count($reviews); $tmp++) {
if ($reviews[$tmp]['freshness'] == 'fresh') {
echo 'Fresh';
} else {
echo 'Rotten';
}
echo '
  • ' . $reviews[$tmp]['quote'] . '
  • ';
    }
    ?>

    ETA: Looked at the API and fixed a couple things.


    ETAx2: For those wanting to see an example of the JSON return from the API...


    {
    "total": 41,
    "reviews": [
    {
    "critic": "Joe Baltake",
    "date": "2010-07-27",
    "freshness": "fresh",
    "publication": "Passionate Moviegoer",
    "quote": "'Toy Story 3': Alternately affecting, hilarious and heartbreaking and the most original prison-escape movie ever made",
    "links": {
    "review": "http://thepassionatemoviegoer.blogspot.com/2010/07/perfectimperfect.html"
    }
    },
    {
    "critic": "Rafer Guzman",
    "date": "2010-07-06",
    "freshness": "fresh",
    "publication": "Newsday",
    "quote": "It's sadder and scarier than its predecessors, but it also may be the most important chapter in the tale.",
    "links": {
    "review": "http://www.newsday.com/entertainment/movies/toy-story-3-andy-grows-up-1.2028598"
    }
    },
    {
    "critic": "Richard Roeper",
    "date": "2010-06-30",
    "original_score": "5/5",
    "freshness": "fresh",
    "publication": "Richard Roeper.com",
    "quote": "The best movie of the year so far.",
    "links": {
    "review": "http://www.richardroeper.com/reviews/toystory3.aspx"
    }
    },
    ...

    No comments:

    Post a Comment

    casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

    In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...