Give help. Get help.

  • # July 14, 2013 at 6:15 pm


    if(isset($trakt->movie->title)) {
    $title = $trakt->movie->title;
    } elseif(isset($trakt->show->title)) {
    $title = $trakt->show->title;
    } else {
    $title = “None”;

    How could I write it to something like this:

    If `$trakt->movie->title` or `$trakt->show->title` isset(), $title = $result?

    # July 14, 2013 at 6:57 pm

    I think I might need to use `empty()` instead of `isset()`

    # July 14, 2013 at 7:18 pm

    Thanks for the resource, @benwalker

    @CrocoDillon Any documentation on `?:`. Can’t seem to find it.

    # July 14, 2013 at 7:19 pm

    It’s the ternary operator @chrisburton.

    Also @CrocoDillon, shouldn’t it be $title = $trakt->movie->title ? $trakt->movie->title : $trakt->show->title ? $trakt->show->title : "None"; Not sure if that’s right though. I never saw the operator with the ? and the : right next to eachother.

    # July 14, 2013 at 7:32 pm

    Oh, ok then @CrocoDillon. Thanks for the tip!

    # July 14, 2013 at 7:38 pm

    Now I’m confused.

    I can just do this?:

    $title = $trakt->movie->title ? $trakt->show->title : “None”;

    # July 14, 2013 at 7:47 pm

    Ok, then it appears that’s not what I’m looking for.

    If `$trakt->movie->title` evaluates to a string and `$trakt->show->title` is empty, the `$title` should equal `$trakt->movie->title`, not `$trakt->show->title` and vice versa.


    if $trakt->movie->title` returns a string and `$trakt->show->title` is empty

    $title = `$trakt->movie->title`

    if $trakt->movie->title` is empty but `$trakt->show->title` returns a string

    $title = `$trakt->show->title`

    # July 14, 2013 at 8:25 pm

    @CrocoDillon I’m grabbing the last value in an array. So there will either be a `movie->title` or `show-title`. There can’t be both and neither one can be empty. One of them will return with a title string.

    I’m trying to simplify an if/elseif.

    ####Current code:

    $trakt = $data->activity[0];

    if(empty($trakt->movie->title)) {
    $title = $trakt->movie->title;
    } elseif(empty($trakt->show->title)) {
    $title = $trakt->show->title;
    } else {
    $title = “None”;

    Basically do this (if it was valid):

    Let’s say the last thing I watched was a `movie`.

    IF $trakt->movie->title OR $trakt->show->title is empty then, $title = whichever isn’t empty

    The result would be the value of `$trakt->movie->title` since I watched a `movie` last. Not a `show`.

    # July 14, 2013 at 9:03 pm

    @CrocoDillon It worked when the last thing I watched was a movie however, if the last thing I watched was a show, I get this:

    Notice: Undefined property: stdClass::$movie in trakt.php on line 10

    10. if($trakt->movie) {
    11. $title = $trakt->movie->title;
    12. } elseif($trakt->show) {
    13. $title = $trakt->show->title;
    14. } else {
    15. $title = “None”;
    16. }

    # July 14, 2013 at 9:06 pm

    @traq THAT WORKED!

    …doing some testing to make sure.

    # July 14, 2013 at 9:15 pm

    Thanks @CrocoDillon, @traq, @benwalker and @srig99.

    Solution (by @traq):

    $title = @$trakt->movie->title
    or $title = @$trakt->show->title
    or $title = “None”;

    # July 14, 2013 at 9:35 pm

    @benwalker I still like to thank those who contribute their time.

    # July 14, 2013 at 10:06 pm

    @traq, Hey buddy, the ? and none is comparable to sql or and null criteria?

    # July 14, 2013 at 10:31 pm

    I have a good knowledge of DB Dev, as you prolly know, doing it for over 10 years (Access, MySql and SQL Server) but I am lately getting intrigued with PHP and how it works in conjunction with DB. Is it like a scripting language to retrieve attribute values from predefined Transact query and place it in html? Or can you actually query tbl with it?

    # July 14, 2013 at 11:02 pm

    @traq, Thanx, I was just thinking lately that I should start learning PHP. I know it will come handy. Thanx again.

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.