Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

PHP and HTML - conditional formatting

I'm working on a phpbb theme and want to format some rows differently depending on how many rows have already been drawn.

Here's my attempt:

Code:
<?php $numbercount = 0; ?>

 

        <!-- BEGIN topicrow -->

 

<?php $numbercount = $numbercount + 1; ?>

 

            <tr>

                <td class="row1" <?php if ($numbercount == 5) echo "style='background-color: #ff0000'" ?> width="100%">

                    <!-- IF topicrow.S_UNREAD_TOPIC --><a href="{topicrow.U_NEWEST_POST}">{NEWEST_POST_IMG}</a><!-- ENDIF -->

                    <!-- IF topicrow.S_HAS_POLL or topicrow.S_TOPIC_MOVED --><b>ORGy AWARD vote:</b> <!-- ENDIF --><a title="{L_POSTED}: {topicrow.FIRST_POST_TIME}" href="{topicrow.U_VIEW_TOPIC}" class="topictitle"><!-- IF topicrow.S_UNREAD_TOPIC --><b><!-- ENDIF -->{topicrow.TOPIC_TITLE}<!-- IF topicrow.S_UNREAD_TOPIC --> ~ You have not yet voted in this award<!-- ENDIF -->

                </td>

                </td>

            </tr>

 

        <!-- END topicrow -->

It should be noted I don't know any php -.-

This basically does nothing.

What I did (or intended to do):


Set a variable to 0:
<?php $numbercount = 0; ?>

Add 1 each time a row is drawn:
<?php $numbercount = $numbercount + 1; ?>

Format differently if it's equal to five:
<?php if ($numbercount == 5) echo "style='background-color: #ff0000'" ?>



What I'm actually planning to do is hide certain rows, but I figure if I can work this out first then it would help.
 
There must be a loop somewhere as it repeats this for each topic row :/

<!-- BEGIN topicrow --> are doing more than just being comments, I don't know what controls it but it somehow magically repeats it for each topic row (I assume).

Otherwise, only one row would ever get drawn.
 
Code:
<?php $numbercount = 0; ?>

 

        <!-- BEGIN topicrow -->

 

<?php $numbercount = $numbercount + 1; ?>

 

            <tr>

 

a<?php echo $numbercount; ?>b

 

... ... ... etc

This returns:

ab ab ab ab ab ab ab ab ab

For some reason it isn't echoing o.O

It won't even do <?php echo "Hello, world!"; ?>

This is odd.
 
Sucks... but for future reference, it may be called multiple times, which would not be equivalent to a loop, since you would be instantiating $numbercount to 0 each time, thus it would always be 1 (after $numbercount = $numbercount + 1).
 
yeah php is executed in the back end code files. The <!--- comments ----> are actually tokens that the php files that power phpBB read and run the resulting functions. The template files are scrubbed of server side scripts to prevent code injection issues, i'm sure. You'll notice that there are if statements done in the same manner in the template files. You may want to try and find some documentation for all of the html tokens they use and try and implement what you want to do through that.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top