November 15, 201015 yr I had created this for a site im doing so thought i'd share it with anyone whos interested in how to create a color chart in php insted of javascript. <?php echo "<table width=\"23%\">"; $ColorArray = array( '00','CC','33','66','99','FF' ); $i = 0; echo "<tr>"; for($j=0; $j<6; $j++){ for($a=0; $a<6; $a++){ for($b=0; $b<6; $b++){ $v = $ColorArray[$j].$ColorArray[$a].$ColorArray[$b]; echo "<td bgcolor='#".$v."'></td>"; $i++; if(!($i%25==0)) { echo "<td></td>"; } if($i%25==0) { echo "</tr><tr>"; } } } } echo "</tr>"; echo "</table>";
November 15, 201015 yr Author And using the same concept i made this one in javascript as well incase anyone prefers JS over PHP, or if thats the primary language u code in. <script language="javascript"> c = '<table width="23%">'; ColorArray = new Array('00','CC','33','66','FF' ); for(j=0;j<5;j++){ for(a=0;a<5;a++){ c +='<tr>'; for(b=0;b<5;b++){ v = ColorArray[j]+ColorArray[a]+ColorArray[b]; c+= '<td bgcolor=#'+v+' style="padding:10px; cursor:pointer;"></td>'; } c+= '</tr>'; } } document.write(c+'</table>'); </script>
Create an account or sign in to comment