Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
Moderator: General Moderators
alok.jethanandani
Forum Newbie
Posts: 1 Joined: Sun Jun 08, 2008 7:53 pm
Post
by alok.jethanandani » Sun Jun 08, 2008 8:01 pm
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?
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Wed Jun 11, 2008 2:58 am
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..
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Wed Jun 11, 2008 3:41 am
Brilliant!