0

I'm quite new to php, so be gentle.....

I have a basic list view that I have set up to match my html/css styles on a sidebar.....but every few listgroup items there are 'header' items on the list that do not inherit the same styles as other listgroup items.

For example, one list group item would have checkboxes and save icons where as the heading list group item would be the same size but would have bold text and no buttons.

This is what I have. On the section below the main one, I have the HTML values for a header list group item. Is it possible to tell the PHP to detect 'step-heading' as a class and then display the following code for all relevant values?

EDIT: I know that in the if-statement that $step-heading is invalid because I have not declared it as a variable...I simply have no idea what to put there otherwise.

            <?php foreach ($tasks as $i => $task) { ?>

                <li class="list-group-item" tabindex="-1">
                    <a class="listgroupwrap" href="#g<?= $i + 1 ?>">
                    </a>
                <span class="step-number-container"> <?=$i + 1 ?>
                </span>
                    <span class="btn-check">
                        <i class="glyphicon glyphicon-ok"></i>
                    </span>
                    <!--<span class="step-checkbox"></span>-->

                        <span class="step-name"><?php echo $task["name"] ?>
                            </span>
                                <span class="step-show-hide">

                                        <span class="btn">
                                            <i class="glyphicon glyphicon-chevron-right">
                                            </i>
                                        </span>
                                </span>
                </li>

            <?php } ?>


<?php
            if ( $tasks == "step-heading" ) {
            ?>
                <li class="list-group-item step-heading" tabindex="-1">
                    <span class="step-number-container">2</span>
                    <a class="listgroupwrap" href="#g<?= $i + 1 ?>">
                    </a>
                    <span class="step-name">Pre-meeting email, send below items:</span>

                </li>
                <?php;
            }
            ?>
7
  • PHP doesn't know or care about your HTML. This code is so messy, I'm not really sure what you're trying to do... Please clarify. Commented Sep 15, 2015 at 21:36
  • Are you saying $task["name"] might contain "step-heading"? Commented Sep 15, 2015 at 21:37
  • Sorry about it being messy. I'm brand new at this. Basically, I have a sidebar that has 10 items in a listgroup (bootstrap). This acts as a navigation bar for the content that will be to the right of the sidebar. Every 2 items on the list there are 'heading' tabs which would be styled slightly differently than the items before it. I'm trying to make sure to loop these styles if I tell the php to output something different if the classes on the header items are seen. Commented Sep 15, 2015 at 21:42
  • Please learn about alternative syntax for control structures when dealing with PHP along with HTML. It makes your code a lot clearer. Commented Sep 15, 2015 at 21:44
  • $task["name"] would not contain step-heading. Step-heading is a class of a list-group-item I have created. Normal list group items would be called li class="list-group-item" where headings would be called "list-group-item heading". Commented Sep 15, 2015 at 21:45

1 Answer 1

1

You can't have it both ways:

        <?php foreach ($tasks as $i => $task) { ?>
                       ^^^^^^---array

        if ( $tasks == "step-heading" ) {
             ^^^^^^---array-as-string

An array in string context is simply the literal word Array.

Perhaps you mean:

        if ( $task == "step-heading" ) {
                  ^---no S

instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.