ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

PHP Loop + Parsing Order + POST variables

July 29, 2012 6:03am

Subscribe [1]
  • #1 / Jul 29, 2012 6:03am

    Ruslan Ka

    63 posts

    Having an issue with logically structuring my code due to the complexity.

    <?php
    ...
    //looping through the 100 items
    for($i=0;$i<100;$i++)
    {
    
    // getting the current post item id
      $id = $_POST['item'.$i.''];
    // selecting the item and showing the title
      $body .= '{exp:channel:entries channel="products" entry_id="{current_id}"}{title}{/exp:channel:entries}';//'{embed="email/product_title" entry_id="2343"}';
     
    }
    ...
    ?>

    Problem 1 If PHP inward than I’m getting the post variable but code doesn’t work
    Probelm 2 If PHP output than the Post variable is not recorder due to the parsing order
    Problem 3 If I’m trying to embed another template it just outputs the string as it is.”{embed="template/page"}”

    Will really appreciate if someone can show me the right direction

    I saw few posts:
    http://loweblog.com/downloads/ee-parse-order.pdf
    http://ellislab.com/forums/viewthread/220736/

    but I believe it cannot be done in my template since I’m running php with loop.

    Thanx.

  • #2 / Jul 30, 2012 2:28pm

    Lisa Wess

    20502 posts

    Hi, Ruslan,

    Can you tell us a bit more about the your core needs?  I ask because, reading your code, the channel entries tag already does exactly what you are asking PHP to do - but you need to have the entry ID in the URL for that to work.

    So I think the question is - where is your entry ID coming from, and what is your end goal?

    Thank you!

  • #3 / Jul 30, 2012 3:20pm

    Ruslan Ka

    63 posts

    I’m getting the post request to my template from mobile application
    which is the following item1=345, item2=456, item3=454389 and etc.

    What I’m trying to do is to read all these variable into php string variable and than email it with HTML formating to the specified email.

    this is how it is suppose to look , sorry for confusing you in the first place.

    $body .= '{exp:channel:entries channel="products" entry_id="'.$id.'"}{title}{/exp:channel:entries}';//'{embed="email/product_title" entry_id="2343"}';
  • #4 / Jul 30, 2012 4:10pm

    Lisa Wess

    20502 posts

    I suspect that parse order might bite you on this one.  Have you considered using something like AB Entry IDs to grab those IDs then work with them?

  • #5 / Jul 30, 2012 6:12pm

    Ruslan Ka

    63 posts

    thanx Lisa , giving it a try now.

  • #6 / Jul 30, 2012 7:25pm

    Lisa Wess

    20502 posts

    Excellent.  Please let me know if that works out for you!

  • #7 / Jul 30, 2012 9:24pm

    Ruslan Ka

    63 posts

    It doesn’t work since I’m facing the same problem where I have to get the POST variable before actually putting it into the query.

    I have tried the query module as well see below.

    And since the template PHP set to OUTPUT I’m not getting the variable, but when I’m setting it to INPUT, I’m getting the output the actual string but not the tag.

    Am I doing something wrong, is there any other way to overcome the this issue?

    for($i=0;$i<100;$i++)
    {
     if(strlen($_POST['item'.$i.''])>0)
     {
      $id = $_POST['item'.$i.''];
      $body .= "{exp:query sql='SELECT title FROM exp_channel_titles WHERE entry_id =".$id."'}{title}{/exp:query}
    ";
      //$body .= '{embed="email/product_title" entry_id="'.$id.'"}';
      $body .= "{exp:ab_entry_ids sql='SELECT title FROM exp_channel_titles WHERE entry_id=".$id."'}{exp:channel:entries entry_id='{ab_entry_ids}'}{title}{/exp:channel:entries}{/exp:ab_entry_ids}";
     }
     
     
     
    }

    Any other suggestions

    I want to get the title and the image_path(Channel Images). Do you think the native php connection to database and query will work?

  • #8 / Jul 30, 2012 10:17pm

    Ruslan Ka

    63 posts

    I end up using php to connect to the database and fetch all the required data.

    The only problem I’m still facing is the Channel Images , since they don’t store the paths in the table, so looking forward from their side to let me know on how I can grab the path of the small preview image.

  • #9 / Jul 31, 2012 10:11am

    Lisa Wess

    20502 posts

    Hi, Ruslan,

    Given how in-depth this is, writing a custom add-on to do what you want may be more ideal, and you won’t need to explicitly connect to the database then.

    I’m glad that you are in touch with the Channel Images publishers as well and that you’ve gotten this far to a solution!

    Please let me know if you need anything else.

  • #10 / Aug 02, 2012 2:35am

    Ruslan Ka

    63 posts

    Yes I believe it could be a good idea,

    The question is where do I start when it comes to writting add ons. 😉

     

  • #11 / Aug 02, 2012 10:13am

    Lisa Wess

    20502 posts

    Hi, Ruslan -

    You would start with the Dev Documentation


    Does that help?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases