Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:55:41+00:00 2026-06-15T04:55:41+00:00

If this were just a static website, i would have four links <li><a href=javascript:void(0)>Action

  • 0

If this were just a static website, i would have four links

<li><a href="javascript:void(0)">Action 1</a></li>
<li><a href="javascript:void(0)">Action 2</a></li>
<li><a href="javascript:void(0)">Action 3</a></li>
<li><a href="javascript:void(0)">Action 4</a></li>

But in this case the links would need to perform different callbacks, output messages and actions depending on who is clicking them. Right now, due to all this complications i have a very messy page. My code goes like this;

<?php
 foreach ($var as $key) {
?>
  <div class="content">
     <li><a href="javascript:void(0)">Action 1</a></li>
     <li><a href="javascript:void(0)">Action 2</a></li>
       <?php
        if(session check){
             $var1 = the ouptut of some function
             $var2 = the output of another function
                  if(another check) {
           ?> 

                     <li><a href="javascript:void(0)">Action 3 type 1</a></li>

               <?php
                   } else{
                        if($var1 === something){
                  ?>
                            <li><a href="javascript:void(0)" onClick="somefunc()">Action 3 type 2</a></li>
                      <?php
                         } 
                         else {
                          ?>
                            <li><a href="javascript:void(0)" class ="colorlink" onClick="somefunc()">Action 3 type 3</a></li>
                        <?php
                            }
                         }
 /* we are done with action 3 and now moving to action 4. Nb: still in the same session check */
        if($var2 == something){
       ?>
           <li><a href="javascript:void(0)" onClick="somefunc()">Action 4 type 1</a></li>

      <?php
        }else{
       ?>
           <li><a href="javascript:void(0)" style ="colorit"onClick="somefunc()">Action 4 type 2</a></li>
     <?php 
          }
/* Now thats the end of everthing in the session check */
/* This else is for session not active */
 } else{
     <li><a href="javascript:void(0)">Action 3</a></li>
     <li><a href="javascript:void(0)">Action 4</a></li>
     }
    ?>

I’m really sorry about how abysmal the indenting is, i really don’t know how to indent on here.
I was wondering if there’s a better way to restructure the code, it doen’t look as bad when it’s been properly indented.
The options i know of are, firstly,i wrap everything round a php tag and echo out the html but the problem is, it still looks as bad with all the nexted if statements.

The second option is the if:,else:,endif; construct, but that doesn’t make it any better.
This is where i need you brilliant minds, how else i can restructure this code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:55:42+00:00Added an answer on June 15, 2026 at 4:55 am

    You may want to look into a PHP Templating Engine. I use PHPTAL on a lot of projects. Twig (not listed there) is also popular I think, possibly because Symfony is popular.

    The goal is to keep PHP code with PHP code and prevent constant breaking in and out of php tags.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just curious if it is syntactically possible to do something like this: static (void)
Question I have a fairly static website with just a few basic PHP usage.
I just created a user control. This control also makes use of my static
This just started happening three weeks or so ago. The content of my website
This just saves time. Since I already have a web applciation. I can just
I fear this just may not be possible, but I'm trying to create a
I understand this is an easy question but for some reason this just isn't
I don't think that this could be done in C#, but posting this just
i have just finished my first app and would like to incorporate ad to
I have a single-page JavaScript application, held within an ASP.NET MVC 3 website. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.