can someone interpret this php line of code?

Last post 10-20-2009 8:36 AM by sanjeev87. 2 replies.

Sort Posts:

  • can someone interpret this php line of code?

    10-14-2009, 11:04 AM
    • Participant
      1,109 point Participant
    • threeo
    • Member since 03-30-2005, 10:26 PM
    • Posts 397

    just one line:

    ($admin_allowed_stores[0] == '*' ? " " : " LEFT JOIN " . TABLE_PRODUCTS_TO_STORES . " p2s ON p.products_id = p2s.products_id ")

    what role does the question mark play?

    what role does the colon play?

    how would you "read" or translate this line into english?

     

     

  • Re: can someone interpret this php line of code?

    10-14-2009, 3:17 PM
    • Contributor
      6,689 point Contributor
    • che3358
    • Member since 09-25-2003, 10:23 AM
    • Cleveland, OH
    • Posts 1,154

    string query = "SELECT * FROM SomeTable p " ;

    if($admin_allowed_stores[0] != "*")

      query += " LEFT JOIN SomeTable p2s ON p.products_id = p2s.products_id";

    Here $admin_allowed_stores[0] is a variable.

    TABLE_PRODUCTS_TO_STORES is a variable also for the second table name.

    in C#

    query += admin_allowed_stores == '*' ? " " : " LEFT JOIN "  + TABLE_PRODUCTS_TO_STORES + " p2s ON p.products_id = p2s.products_id ";

     

    "Object reference not set to an instance of an object"
  • Re: can someone interpret this php line of code?

    10-20-2009, 8:36 AM
    • Member
      361 point Member
    • sanjeev87
    • Member since 09-22-2009, 8:39 AM
    • Bhubaneswar,Bangalore
    • Posts 70

    ($admin_allowed_stores[0] == '*' ? " " : " LEFT JOIN " . TABLE_PRODUCTS_TO_STORES . " p2s ON p.products_id = p2s.products_id ")

    this is the conditional operator syntax

    x=condition?truevalue:falsevalue;

    here the condition is if($admin_allowed_stores[0] == '*')

    if this is true then " " (the true condition )is assigned.

    if the condition is false " LEFT JOIN " . TABLE_PRODUCTS_TO_STORES . " p2s ON p.products_id = p2s.products_id ")


    "." is string concatination operator used in php.in dot net "+" is used for the same purpose.

    please mark it as answer if it satisfy.if you still have any query please feel free to ask.


    thanks

    sanjeev





    It feels good when someone really appreciate your efforts.please mark as answer if it has helped you.This can be helpful for those who face the same problem in future.
Page 1 of 1 (3 items)