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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:09:15+00:00 2026-06-14T12:09:15+00:00

I have a PHP while loop, which displays the content of a database, in

  • 0

I have a PHP while loop, which displays the content of a database, in a table.
I would like to make all the rows in the table different colors.

But not just random. I would like them have different shades of red, where the first row is most red, and then the rest fades into a lighter red.

As an exemple, I would like the same effect as the iPhone App: Clear.
Photo example: http://www.realmacsoftware.com/_resources/clear/images/ss_pinch.png

I’ve tried to make the effect with -nth in CSS and some jQuery, but just couldn’t figure it out. I hope you will give it a try.

Here is the code:

<table>


<tr>
<td align="center"><strong>Navn:</strong></td>
<td align="center"><strong>Spørgsmål:</strong></td>
<td align="center"><strong>Tid:</strong></td>

</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['name']; ?></td>
<td><? echo $rows['ask']; ?></td>
<td><? echo $rows['time']; ?></td>


<?php
}
?>

</tr>
</table>
  • 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-14T12:09:15+00:00Added an answer on June 14, 2026 at 12:09 pm

    If you need a different color for each element, then a static CSS file is not able to describe that. You could generate a CSS file on the fly, but I opt for inline styles instead. Don’t use inline styles if you can use a static CSS file.

    For a simple linear interpolaction from red to white, adhering to your coding style. I’ve also removed an extra </div> that didn’t belong there:

    <?php
    $num_rows=mysql_num_rows($result);
    $cur_row=0;
    while($rows=mysql_fetch_array($result)){
    $color=intval(256*$cur_row/($num_rows-1));
    $cur_row++;
    ?>
    <tr style="background:rgb(256,<? echo $color.','.$color;>);">
    <td><? echo $rows['name']; ?></td>
    <td><? echo $rows['ask']; ?></td>
    <td><? echo $rows['time']; ?></td>
    <?php
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have setup a simple while loop which returns all images in a table
Learning php! I have a sql database which contains a table called 'images' which
I have PHP script works without problems, like this : while($row4 = mysql_fetch_array($result4)) {
I have this loop which basically displays a block on the page with an
I have a html table(grid) which displays a few records for me.I want it
Guys this is my first question. I have a table which displays the students
I have a wordpress page which has two loops like so... <?php global $post;
I have a while loop in php that fetches results of a query (a
I would like to know how to solve this issue with a while loop
I have this simple while loop which retrieves data from a mysql query and

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.