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

  • Home
  • SEARCH
  • 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 6958685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:10:21+00:00 2026-05-27T15:10:21+00:00

I have a block of PHP code that looks like this: $flag = false;

  • 0

I have a block of PHP code that looks like this:

$flag = false;
if (empty($links))
{
    echo '<h1>You have no uploaded images</h1><br />';
}

foreach ($links as $link)
{   
    $extension  = substr($link, -3);
    $image_name = ($extension == 'peg') ? substr($link, -15) : substr($link, -14);  

    ($delete_submit) ? deleteImage('.' . $image_name, $link) : '';

    echo '<div>';
        echo '<table>';

        echo '<tr><td class="fullwidth"><a class="preview_img" href="' . $link . '"><img src="' . $link . '" title="Click to enlarge" width="300" class="thumb" /></a></td></tr>';

        echo '<tr><td><span class="default">Direct:</span>&nbsp;';
        echo '<input type="text" readonly="readonly" class="link-area" onmouseover="this.select();" value="' . $link . '" />'; 
        echo '</td></tr>';

        echo ($flag) ? '<hr /><br>' : '';

        echo '</table>';
        echo '<br>';
    echo '</div>';

    $flag = true;
}

I want the <div> to include a different class based on if it is even or odd. If it is even, it gets X class, if it’s odd it gets Y class.

How do I do this in my case? I’m totally clueless and I don’t know how to start!

  • 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-27T15:10:22+00:00Added an answer on May 27, 2026 at 3:10 pm

    Initialise a variable $count=0; before the loop. Then place the following in the loop: ++$count%2?"odd":"even".

    $count = 0;
    foreach ($links as $link)
    {   
        $extension  = substr($link, -3);
        $image_name = ($extension == 'peg') ? substr($link, -15) : substr($link, -14);  
    
        ($delete_submit) ? deleteImage('.' . $image_name, $link) : '';
    
        echo '<div class="' . (++$count%2 ? "odd" : "even") . '">';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some jQuery that looks like this: $.ajax({ type: POST, url: /problems/vote.php, dataType:
I have a code snippet written in PHP that pulls a block of text
I have an ajax request that looks like this, $(#frmProducts).submit(function(){ var dataSet = $(#frmProducts).serialize();
I have a block of code that works and I wanted to ask what
I have a block of JSP code that needs to be used in several
I have a block of code that basically intializes several classes, but they are
I have a block of code that is repeated within a DB2 stored procedure.
I have this block of code: users = Array.new users << User.find(:all, :conditions =>
I have two DIV elements. HTML looks like this: <div id=first><div id=second></div></div> The CSS
So, I have this PHP code: $tabid = getTabid($module); if($tabid==9) $tabid=9,16; $sql = select

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.