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 8092879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:22:52+00:00 2026-06-05T20:22:52+00:00

I use a paging system like this: <?php $p = $_GET[‘p’]; switch($p) { case

  • 0

I use a paging system like this:

<?php
$p = $_GET['p'];

switch($p)
{
    case "start":
        $p = "pages/start.php";
        $currentPageId = 1;
    break;

    case "customers":
        $p = "pages/customers.php";
        $currentPageId = 2;
    break;

    default:
        $p = "pages/start.php";
        $currentPageId = 1;
    break;
}
?>

I want to set css class="active" to the menu item of the page i’m on.

It works if I print <li> items like this:

<li><a href="?p=start" <?php if ($currentPageId == 1) {echo "class='active'";}else {} ?>>Start</a></li>

But I would like to use ternary operator instead. I tried this code but it doesn’t work:

<li><a href="?p=start" <?php ($currentPageId == '1') ? 'class="active"' : '' ?>>Startsida</a></li>

Any idea why?

EDIT
So the problem was I was missing an echo. Now let me extend the question a bit…

I need to encapsulate my entire <ul> inside the <?php ?> tags. So what I would like is something like this:

echo "<div id='nav'>";
 echo "<ul>";

   echo "<li><a href='?p=start' /* ternary operator to match if the page I'm on is equal to $currentPageId as defined in the paging system (above), if so set class='active' else do nothing*/>Start</a></li>;
   echo "<li><a href='?p=customers' /* ternary operator to match if the page I'm on is equal to $currentPageId as defined in the paging system (above), if so set class='active' else do nothing*/>Customers</a></li>;


 echo "</ul>";
echo "</div>";

I need to do this because I will display the links based on ifstatements.. “if user is admin display this link, else don’t” … Anyone got a solution?

  • 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-05T20:22:52+00:00Added an answer on June 5, 2026 at 8:22 pm

    You are missing an echo:

    <li><a href="?p=start" <?php echo (($currentPageId == '1') ? 'class="active"' : '') ?>>Startsida</a></li>
    

    That should do the trick.


    Addressing the second question:

    <?php
    if($something == true) {
        echo "<div id='nav'>"."\n<br>".
                "<ul>"."\n<br>".
                    '<li><a href="?p=start"'. (($currentPageId == '1') ? 'class="active"' : '') .'>Startsida</a></li>'."\n<br>".
                    '<li><a href="?p=customers" '. (($currentPageId == '1') ? 'class="active"' : '') .' >Customers</a></li>'."\n<br>".
                "</ul>"."\n<br>".
                "</div>"."\n<br>";
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the ObjectDataSource with enabled paging. This requires me to
Most OSes use paging for virtual memory. Why is this? Why not use segmentation?
To use flickr as an example, a request URL looks something like this: 'http://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&api_key='
I use telerik:RadComboBox Like this : <telerik:RadComboBox runat=server ID=RadComboBox1 EnableLoadOnDemand=true ShowMoreResultsBox=true EnableVirtualScrolling=true CollapseDelay=0 Culture=ar-EG
Does Android support virtual memory concept? I read it does use paging but not
I use the Paging-Functionality of the UIScrollView for paging several Views (an array of
I use the ASPxGridView with paging, pager settings is next: <SettingsPager Mode=ShowPager Position=Bottom Visible=true>
I use infinite scroll for paging. And it was working fine until today. Today
I use jquery pagination plugin for paging... If there is one pagination plugin there
I'm using preg_replace to create urls for modrewrite based paging links. I use: $nextURL

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.