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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:00:31+00:00 2026-05-27T17:00:31+00:00

I have a table with a row of 3 div’s then another row or

  • 0

I have a table with a row of 3 div’s then another row or 3 div’s then another and then another.

But what I’m trying to achieve is to highlight every other row. And each row contains 3 div’s.

So the first row will be .mydiv .even and then the .even‘s will be grey. Then the next row will be .mydiv .odd and then the .odd‘s will be white.

I am using this code from css-tricks.com ($xyz++%2) to make every other div a different class.

All help is apreciated.


This is my code

$get_new_games = mysql_query("SELECT game_title,game_description,id from games ORDER BY added_date LIMIT 10");
while ($row = mysql_fetch_array($get_new_games)) {
$new_game_title = $row['game_title'];
$new_game_description = $row['game_description'];
$new_game_id = $row['id'];
$new_games_display .= '<div class = "game_module class-'.($xyz++%2).'"><img src = "game_thumbnails/'.$new_game_id.'/_thumb_100x100.png" class = "game_img"></div>';
}
  • 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-27T17:00:32+00:00Added an answer on May 27, 2026 at 5:00 pm

    It would make more sense to add the class to the row, to output the table rows in PHP, use something like this:

    <?php for ($i = 0; $rows[$i]; $i ++): ?>
    <tr class="<?php echo $i % 2 ? 'odd' : 'even'; ?>">
      <td>
        <div />
      </td>
      <td>
        <div />
      </td>
      <td>
        <div />
      </td>
    </tr>
    <?php endfor; ?>
    

    The modulo operator % will return the remainder of the division, in this case the division is by two and any equal number will give a remainder of zero, and any unequal number will give a remainder of one.

    The selector for the div would then be:

    tr.odd td > div
    tr.even td > div
    

    this will make sure that only the top div in each row is selected.

    UPDATE:

    From the code you’ve supplied it doesn’t really appear you’re using a table at all (maybe you meant it in a looser sense than the actual HTML element?). Going by your code you already use the modulo in the way described above, but you need to change the following.

    $xyz = 0;
    $get_new_games = mysql_query("SELECT game_title,game_description,id from games ORDER BY added_date LIMIT 10");
    while ($row = mysql_fetch_array($get_new_games)) {
      $new_game_title = $row['game_title'];
      $new_game_description = $row['game_description'];
      $new_game_id = $row['id'];
      $new_games_display .= '<div class = "game_module class-'.($xyz++%2 ? 'odd' : 'even').'"><img src = "game_thumbnails/'.$new_game_id.'/_thumb_100x100.png" class = "game_img"></div>';
    }
    

    I’ve added the first line to initialize the variable to zero and changed the $new_games_display-line to ($xyz++%2 ? 'odd' : 'even'). This will ensure that every other div has the class class-odd and the rest class-even.

    The only issue I’m having is that the code you supplied doesn’t really correspond to your initial problem, with rows of three divs, maybe I’m missing something — feel free to supply more code and I’ll be able to help you more.

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

Sidebar

Related Questions

I have a table where each row contains some data ( data-id ) and
I have a data table filled with text in each table row. How do
I have a table where each row has a description field as well as
I have a table where each row has 13 TD elements. I want to
I have a table where every row has a unique id. The last table
I am trying to display every odd instance of a table row, however there
I am trying to animate a table row sliding up, then adding a new
I currently have this code HTML <div class=table> <div class=header-row> <div class=header-cell>First Name</div> <div
I am reading a table row from one page, and then trying to put
I have a div-table that is working fine with about 4 columns but now

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.