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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:31:14+00:00 2026-05-25T11:31:14+00:00

I have a while loop and each one displays a <li></li> in a list,

  • 0

I have a while loop and each one displays a <li></li> in a list, is there a way to tell php that every other loop should echo say:

<li style="background: #222;"></li>

and in my css I would have another colour #111 set as default so users of my site can easily determine which row of data they are seeing?

my code as requested:

function user_details($dbc, $q, $details) {
echo '<ul class="userlist">';
while ($user = $q -> fetch(PDO::FETCH_ASSOC)) {

    echo '<li><span>(' . $user['id'] . ')</span> <a href="/viewaccount?id=' . $user['id'] . '">' . $user['username'] . '</a><div>';

    if ($user['admin'] > 0) {
        echo '<img class="Tooltip" src="gameimages/admin.png" width="18" height="18" title="Is game admin." alt="" />';
    }

    echo '<img class="Tooltip" src="gameimages/' . $user['gender'] . '.png" width="18" height="18" title="' . $user['gender'] . '" alt="" />';

    $last_active = time() - $user['last_active'];
    $seconds = $last_active % 60;
        $minutes = ($last_active - $seconds) / 60;
    if ($minutes <= 4) {
    echo '<img class="Tooltip" src="gameimages/active5.png" width="18" height="18" alt="" title="';
        if ($seconds == 0) {
            echo 'Last active ' . $minutes . ' minutes ago." />';
        }
        elseif ($minutes == 0) {
            echo 'Last active ' . $seconds . ' seconds ago." />';
        }
        else {
            echo 'Last active ' . $minutes . ' minutes and ' . $seconds . ' seconds ago." />';
        }
    }
    elseif ($minutes <= 9) {
        echo '<img class="Tooltip" src="gameimages/active10.png" width="18" height="18" alt="" title="';
        if ($seconds == 0) {
            echo '<strong>Last active ' . $minutes . ' minutes ago." />';
        }
        else {
            echo 'Last active ' . $minutes . ' minutes and ' . $seconds . ' seconds ago." />';
        }
    }
    elseif ($minutes <= 14) {
        echo '<img class="Tooltip" src="gameimages/active15.png" width="18" height="18" alt="" title="';
        if ($seconds == 0) {
            echo 'Last active ' . $minutes . ' minutes ago." />';
        }
        else {
            echo 'Last active ' . $minutes . ' minutes and ' . $seconds . ' seconds ago." />';
        }
    }

    if ($user['subscriber'] > 0) {
        echo '<img class="Tooltip" src="gameimages/subscriber.png" width="18" height="18" title="Subscriber with ' . $user['subscriber'] . ' days left." alt="" />';
    }

    echo '</div>';

    echo '<a href="#"><img class="Tooltip" src="gameimages/sendmessage.png" width="18" height="18" title="Send ' . $user['username'] . ' a message." alt="" /></a>';

    $is_friend = $dbc -> prepare("SELECT id, friend_id FROM friends WHERE id = ? && friend_id = ?");
    $is_friend -> execute(array($details['id'], $user['id']));
    $friend_request = $dbc -> prepare("SELECT id, id_to FROM friend_requests WHERE id = ? || id_to = ? && id = ? || id_to = ?");
    $friend_request -> execute(array($user['id'], $details['id'], $details['id'], $user['id']));
    if ($is_friend -> rowCount() > 0) {
        echo '<img class="Tooltip" src="gameimages/isfriend.png" width="18" height="18" title="Friend request sent to ' . $user['username'] . '." alt="" />';
    }
    elseif ($friend_request -> rowCount() > 0) {
        echo '<img class="Tooltip" src="gameimages/friendrequested.png" width="18" height="18" title="There is a request pending to be friends with ' . $user['username'] . '." alt="" />';
    }
    else {
        echo '<a href="/confirm?action=addfriend&amp;id=' . $user['id'] . '"><img class="Tooltip" src="gameimages/addfriend.png" width="18" height="18" title="Add ' . $user['username'] . ' as a friend." alt="" /></a></li>';
    }
}
echo '</ul>';
 }

It is in a function at the min, basically each other row should have another background 🙂

  • 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-05-25T11:31:14+00:00Added an answer on May 25, 2026 at 11:31 am

    You could use an boolean flag to keep track is it odd or even row, ie

    $isOdd = true;
    while(...){
      if($isOdd) echo '<li style="background: #222;"></li>';
      else echo '<li></li>';
      $isOdd = ! $isOdd;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two while loops running one after the other (not inside of each
I have a script that uses a simple while loop to display a progress
So I have a Linux program that runs in a while(true) loop, which waits
I have to delete every word containing at least one number from each file
The while loop I have while reading in from a file doesn't break. I'm
I have a tabled view in a while loop, where a user can view
I'm trying to understand how a while loop looks in IL. I have written
I have a Label, whose content is displayed by a while loop. when i
Using parent child relationship where a parent can have children while each child has
I have one 'main' thread that creates an array of objects of class SlowData

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.