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.

entry_id doesn’t change in weblog:entries loop

July 08, 2007 1:15pm

Subscribe [3]
  • #1 / Jul 08, 2007 1:15pm

    SteveJohnson

    8 posts

    I’m having a weird problem. In a list of entries, the {entry_id} tag is duplicating itself. All of the other tags that relate to the entry are fine. It seems that the {exp:weblog:entries} loop is picking up the initial entry_id and using it for the rest of the entries. See screenshot.

    relevent code:

    <?php $username = "{embed:username}";?>
    {exp:query sql="select entry_id from exp_weblog_data where field_id_32 = '<?=$username?>' LIMIT 1"}
    
    <table class="projects" width="670" border="0" cellpadding="0" cellspacing="0">
        <caption align="top">{embed:company}  Project Report</caption>
        <tr class="tablehead">
            <td width="10" class="name"> </td>
            <td width="160" class="name">Name</td>
            <td width="100"><div align="center">Priority</div></td>
            <td width="100"><div align="center">Due Date </div></td>
            <td width="300"><div align="center">Comments</div></td>
        </tr>
        {exp:weblog:entries weblog="projects" orderby="project_priority|project_duedate|title" sort="desc|asc|asc"}
    {if "{embed:username}" == "{project_client}"}
            <tr valign="top" class="entry">
            <td class="name"><strong>{entry_id}</strong></td>
            <td class="name"><strong>{title}</strong></td>
            <td class="priority">{project_priority}</td>
            <td class="duedate">{project_duedate format="%n-%j-%y"}</td>
            <td class="comments">{project_comments}</td>
        </tr>
        <tr class="notes"><td colspan="5">Notes: {project_notes}</td></tr>
        <tr><td colspan="5"> </td></tr>
    {/if}
    
        {/exp:weblog:entries}
    </table>
    {/exp:query}

    This is a 3rd level embedded template (so I could use nested queries—works fine). All of the other fields display ok—title, project_priority, etc.

    Any ideas or am I missing something stupidly obvious?

  • #2 / Jul 08, 2007 1:24pm

    SteveJohnson

    8 posts

    *YEOW*

    I found the problem. I was SELECTing just to get a group of entries, so I just picked ‘entry_id’ to get. Unfortunately, the {weblog:entries} loop wasn’t writing over the initiation of ‘entry_id’ as an available variable.

    A simple change to “SELECT entry_id as entryid…” solved it.

  • #3 / Jul 08, 2007 11:19pm

    Derek Allard

    3168 posts

    I love self-healing EE installs 😉

    Glad you got it working Steve!

  • #4 / Jul 09, 2007 12:27am

    SteveJohnson

    8 posts

    It turns out, after my hair-pulling, that my client doesn’t want to display the entry id #s. What he wants is a simple incrementing number for each table row that is output. And that’s something I can’t figure out how to do. If I use {count} the number that displays reflects how many times EE’s been through the loop until the {if} condition is met.

    I wish there were some way to tell EE “if you display this, increment the counter”. I have to have PHP turned on to parse on input, so any incrementing within the loop increments the counter every time through regardless of whether the {if} condition is true or not, just like {count}.

    I’m frustrated, terribly.

  • #5 / Jul 09, 2007 7:56am

    Derek Allard

    3168 posts

    So Steve, do you want

    1. Entry Title
    2. Entry Title
    3. Entry Title
    etc…

    If so, count does sound like the way to go.  To get you started off, could you (1) upgrade to the latest build (released last night) and then (2) put up a test template using count and post the url and code into this thread?

  • #6 / Jul 09, 2007 2:02pm

    SteveJohnson

    8 posts

    Derek, I’ll PM you with the URL. The client believes this is sensitive information. You can show it to whomever you think needs to see.

    I can’t upgrade to the latest version; client doesn’t want to at the moment ($). He is on 1.5.0 Build: 20060906. Maybe if the version is an issue I can get him to spring for the upgrade, but I’m not hopeful.

    I copied the template group to another group and removed the member permissions so you won’t have to log in. What you’ll see is the administrator version that lists all jobs; logged-in users see only their individual jobs.

    The general setup is this: clients are assigned to the ‘clients’ member group, and their username is added to a custom field dropdown list named project_client.

    Weblog data is all custom fields (excluding {title}, of course): project_client, project_priority, project_duedate, project_comments, project_notes.

    In template ‘table’, I get the list of usernames in the clients member group. {exp:query} loops through results, so for every username, the admin_table template is called, with username and company variables passed.

    In admin_table, the query is to extract the posts of the current client, as passed via username in the {embed} statement. The client version of this doesn’t use the query, but the count problem remains. PHP is parse on input.

    For every distinct client, the top of the table is output, then the entries tag is used to loop through each entry, looking for an entry where the project_client field matches the current username. If they match, a table row is output.

    This is where the problem lies. The {count} variable is incremented every trip through the weblog:entries tag, regardless of whether there is a match or not. It counts loops. I’ve tried putting a PHP variable in and incrementing it, but it does the same thing. I’ve also tried, in the client’s version, setting PHP to parse on output, but it doesn’t increment the variable because the table’s already rendered.

    The code.

    Index:

    {assign_variable:my_template_group="testing123"}
    {embed="{my_template_group}/head"}
    <title>Van Wyk Design</title>
    </head>
    <body>
    <div align="center">
    <div id="centerframe">
    {embed="projects/nav"}
    
    {embed="testing123/table"}
    
    {embed="vanwyk/bottom"}
    </div>
    </div>
    </body>
    </html>

    table:

    <div id="projectdiv">
    {exp:query sql="SELECT username, screen_name as company FROM exp_members WHERE group_id = '6' ORDER BY screen_name" }
    {embed="testing123/admin_table" username="{username}" company="{company}"}
    {/exp:query}
    </div>

    admin_table:

    <?php $username = "{embed:username}";?>
    {exp:query sql="select entry_id as entryid from exp_weblog_data where field_id_32 = '<?=$username?>' LIMIT 1"}
    
    <table class="projects" width="670" border="0" cellpadding="0" cellspacing="0">
    <caption align="top">{embed:company}  Project Report</caption>
    <tr class="tablehead">
    <td width="20" class="name"> </td>
    <td width="160" class="name">Name</td>
    <td width="100"><div align="center">Priority</div></td>
    <td width="90"><div align="center">Due Date </div></td>
    <td width="300"><div align="center">Comments</div></td>
    </tr>
    
    {exp:weblog:entries weblog="projects" orderby="project_priority|project_duedate|title" sort="desc|asc|asc"}
    {if "{embed:username}" == "{project_client}"}
    <tr valign="top" class="entry">
    <td class="name">{count}</td>
    <td class="name">{title}</td>
    <td class="priority">{project_priority}</td>
    <td class="duedate">{project_duedate format="%n-%j-%y"}</td>
    <td class="comments">{project_comments}</td>
    </tr>
    <tr class="notes"><td colspan="5">Notes: {project_notes}</td></tr>
    <tr><td colspan="5"> </td></tr>
    {/if}
    
    {/exp:weblog:entries}
    </table>
    {/exp:query}

    So there you have it. I’m at a loss as to what to do; I had to do the setup this way because the client isn’t tech-oriented enough to go through setting up a specific weblog for each client. He wants to do as little as possible, which is add the client as a member. If I took some time to write a plugin that would populate the project_clients field rather than him having to get in and add a name, he would be in seventh heaven. That’s what I’m dealing with.

  • #7 / Jul 09, 2007 3:15pm

    Derek Allard

    3168 posts

    1.5?  I’d strongly encourage you to upgrade.

    I’ll try a generic strategy here.  What you’ll need to do is make the conditional part of the php.  So, set PHP to output and try this

    <?php
    $counter = 0;
    ?>
    
    
    {exp:weblog:entries weblog="projects" orderby="project_priority|project_duedate|title" sort="desc|asc|asc"}
    {if "{embed:username}" == "{project_client}"}
    <?php
    if ('{embed:username}' == '{project_client}') {
    $counter++;
    echo $counter;
    }
    ?>
    code
    {/if}
    
    {/exp:weblog:entries}

    This is also a bit beyond what we can offer as formal technical support, so I’m moving this thread into community support for you.

    Good luck!

  • #8 / Jul 09, 2007 3:30pm

    SteveJohnson

    8 posts

    OK, question. Currently, I have to set the {embed:username} variable in PHP so I can use it in the {exp:query} tag, which necessitates PHP on input. How can I just use the {embed:username} variable in the sql statement so I can turn on PHP for output? Everything I’ve tried hasn’t worked (enclosing in quotes, etc.).

    That’s a cool technique, BTW. I didn’t really realize I could do that. I have so much to learn…

  • #9 / Jul 09, 2007 3:38pm

    Derek Allard

    3168 posts

    I don’t think it’ll work on PHP on input due to parse order, so the only other work around I can think of is a custom field that has “1” in it, and you just keep adding them up as you loop.

    You might also want to put in a feature request for a new variable that counts only entries shown.

  • #10 / Jul 09, 2007 3:46pm

    SteveJohnson

    8 posts

    According to the parse order, {embed:foo} variables are among the first parsed, before any {exp:} tags. Accordingly, I should be able to use the {embed:username} variable in the {exp:query} statement, but I can’t get it to work. Any ideas, anyone?

    BTW, thanks, Derek for taking the time to help.

  • #11 / Jul 09, 2007 3:49pm

    Derek Allard

    3168 posts

    Was chatting with Lisa, and she suggested that if you are limiting by username, you could get away with using the username parameter it would work for you.  Does

    username="{embed:username}"

    give you any luck?

  • #12 / Jul 09, 2007 4:06pm

    SteveJohnson

    8 posts

    After trying, I remembered that I’m not really limiting by username, but by custom field contents, so no, it doesn’t work.

  • #13 / Jul 10, 2007 6:26am

    silenz

    1651 posts

    At least in 1.5.2

    {exp:query sql="select entry_id from exp_weblog_data where field_id_32 = '{embed:username}' LIMIT 1"}

    works just fine. Is it different in 1.5?

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

ExpressionEngine News!

#eecms, #events, #releases