Page 1 of 1

Gradient (based on the number of records)

Posted: Sun Jun 08, 2008 8:01 pm
by alok.jethanandani
Please visit this url to get a preview of what i'm trying to accomplish:
http://classes.design.ucla.edu/Spring08 ... /index.php

To make that gradient dynamic this is the code im working on:

Code: Select all

 
                $sql = "SELECT * FROM playlist ORDER BY DT DESC";
        $result = mysql_query($sql);
        
        $num_rows = mysql_num_rows($result);
        
        [b]for ( $i = $num_rows; $i < $num_rows + 1 && $i > 0; $i++) {
            $rgb = 255-(230/$i);
        }   [/b]
 
Does that For Loop right?

Code: Select all

 
 
<div id="media">
        <ul>
            <?php 
            $sql = "SELECT * FROM playlist ORDER BY DT DESC";
            $result = mysql_query($sql);
            
            while ( $row = mysql_fetch_assoc($result) ) {
                echo "<li><a href='#'><font style='color:rgb(255,255,255);'>{$row['title']}</font></a></li>";
            }
            
            ?>
            
         </ul>
    </div>
    
</div>  
 
I need that For Loop to count down in the rgb space. How can this be done?

Re: Gradient (based on the number of records)

Posted: Wed Jun 11, 2008 2:58 am
by onion2k
Assuming you want to start at X and go down to Y, divide the difference by the number of records and then subtract that amount from the RGB values at each step.

eg

Code: Select all

$sql = "SELECT * FROM playlist ORDER BY DT DESC";
$result = mysql_query($sql);
 
$start = 255;
$end = 128;
$records = mysql_num_rows($result);
$step = round(($end-$start)/$records);
 
$color = $start;
 
while ( $row = mysql_fetch_assoc($result) ) {
  echo "<li><a href='#'><font style='color:rgb(".$color.",".$color.",".$color.");'>{$row['title']}</font></a></li>";
  $color -= $step;
}
 
Not tested that code..

Re: Gradient (based on the number of records)

Posted: Wed Jun 11, 2008 3:41 am
by Benjamin
Brilliant!