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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:57:51+00:00 2026-06-13T19:57:51+00:00

Im wondering if its possible with PHP to add a class to X record

  • 0

Im wondering if its possible with PHP to add a class to X record returned. I know I can do this with JS only I’d like it to have the class added as the records are returned.

I have the following loop in my PHP, From what I’ve found in google I need to add a counter to do this only I’ve been unsuccessful so far…

while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
        echo '<div class="entry span3"><span class="name">' . $row['First_Name'] . ' ' . $row['Surname'] . "</span>";
        echo '<img src="' . $row["picture_1"] . '" alt="' . $row['First_Name'] . ' ' . $row['Surname'] . ', text ' . $row['Date'] . ' ">';
        echo '<span class="from">seen in ' . ucwords($row["Location_County__Seen"]) . '</span><a href="/' . strtolower($row["Surname"]) . '/' . $row["ID"] . '">View Profile</a></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-06-13T19:57:52+00:00Added an answer on June 13, 2026 at 7:57 pm

    In front of your while, add $c = 1

    Before the end of your while loop, add $c++;

    Then, modify your first line:

    echo '<div class="entry span3"><span class="name">'

    To

    echo '<div class="entry span3';
    if (($c % 4) == 1) echo ' newclassname ';
    echo '"><span class="name">'
    

    For the final result:

    $c = 1;
    while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
        echo '<div class="entry';
        if (($c % 4) == 1) echo ' newclassname ';
        echo ' span3"><span class="name">' . $row['First_Name'] . ' ' . $row['Surname'] . "</span>";
        echo '<img src="' . $row["picture_1"] . '" alt="' . $row['First_Name'] . ' ' . $row['Surname'] . ', text ' . $row['Date'] . ' ">';
        echo '<span class="from">seen in ' . ucwords($row["Location_County__Seen"]) . '</span><a href="/' . strtolower($row["Surname"]) . '/' . $row["ID"] . '">View Profile</a></div>';
    
        $c++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering if its possible to have Netbeans display PHP Documentation for functions/methods/classes
I'm wondering if its possible to add new class data members at run-time in
I have no experience with PHP and I am wondering if this is possible:
I am wondering if its possible to have a an (||)or or (&&)and operator
I was wondering if its possible to add custom header with classic asp. In
I am wondering if its possible to get $(this).scrollTop() value after an anchor jump.
I'm wondering if its possible to resize flash with javascript. I can't change any
I am wondering if its possible to declare a symbol constant in php I
i'm wondering if it's possible to add a php file in your themes folder
I was wondering if its possible, to loop through an array but have each

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.