PHP - Php And Colors
Hey,
We have a software program, where a user can set the color of different tasks and stuff. When the save it, the value in the database is an int. How would I go about converting that into a hex value. Red: 255 Green: 33280 Grey: 13026246 Any ideas, thanks Similar TutorialsThe intention is to alternate table rows background color between classes "row0" and "row1" defined elsewhere. Is this code valid ? <?php $rowclass = 0; ?> <table ... > <!-- BEGIN poll_option --> <tr class="row{ROWCLASS}"> ............ tried also : class="row<?= $rowclass ?>" <td> .......... </td> </tr> <?php $rowclass = 1 - $rowclass; ?> <!-- END poll_option --> </table> In the source I cannot see any value for "$rowclass". Thanks for helping. I've checked it seems a million tutorials that have all been simplat, but i have been unable to get alternating row colors working when pulling info from a mysql database and displaying in a table. Any suggestions? Code: [Select] <html> <head> <LINK href="style.css" rel="stylesheet" type="text/css"> <script language="JavaScript"> function checkAll(){ for (var i=0;i<document.forms[0].elements.length;i++) { var e=document.forms[0].elements[i]; if ((e.name != 'allbox') && (e.type=='checkbox')) { e.checked=document.forms[0].allbox.checked; } } } </script> </head> <body> <form id="form1" name="form1" method="post" action="handler.php"> <div align="center"><h1>Unprocessed Applications</h1><input type="submit" name="button" id="button" value="Submit" /></div> <table id="mytable" cellspacing="0"> <tr> <th scope="col"><strong>Date</strong></th> <th scope="col"><strong>ID</strong></th> <th scope="col"><span class="style1 style3"><strong>First Name</strong></span></th> <th scope="col"><span class="style1 style3"><strong>Last Name</strong></span></th> <th scope="col"><div align="center"><span class="style3"></span></div>Check All -></th> <th scope="col"><div align="center"><input type="checkbox" value="on" name="allbox" onclick="checkAll();"/><br /></div></th> </tr> <?php do { ?> <tr> <td width="28%"><span class="style1"><?php echo date('F j, Y - g:ia', $row_update['timestamp']); ?></span></td> <td width="7%"><?php echo $row_update['id']; ?></td> <td width="17%"><?php echo $row_update['first_name']; ?></td> <td width="28%"><?php echo $row_update['last_name']; ?></td> <td width="15%"><div align="center"><?php echo "<a href=\"https://www.*******/index.php?id=". $row_update['id']."\" target='_blank'>View & Print</a>"; ?></div></td> <td width="5%"><div align="center"> <input type="checkbox" name="checkbox[]" value="<?php echo $row_update['id'] ?>" /> <label for="checkbox"></label> </div></td> </tr> <?php } while ($row_update = mysql_fetch_assoc($update)); ?> </table> <label for="button"></label> <div align="center"><input type="submit" name="button" id="button" value="Submit" /></div> </form> </body> </html> Hi, I wrote the function below. It switches out one color for another. The pictures going in are css sprites with various colors and a white background. So.. sprite 1 might by blue and sprite 2 might be green. The function would be run twice to replace the blue + green with whatever colors were required. /** * Changes the color of a graphic. * $settings = array ( * 'icon' * 'new_icon' * 'old_color' = array * 'new_color' = array * ); */ function updateIconColor($settings=array()) { // Create Image $image = imagecreatefrompng($settings['icon']); // Convert True color image to a palatte imagetruecolortopalette($image, false, 255); // Restore Alpha $white = imagecolorclosest($image, 255, 255, 255); imagecolortransparent($image, $white); // Find + Set color $index = imagecolorclosest($image, $settings['old_color'][0],$settings['old_color'][1],$settings['old_color'][2]); imagecolorset($image, $index, $settings['new_color'][0], $settings['new_color'][1], $settings['new_color'][2]); // Restore Alpha imageAlphaBlending($image, true); imageSaveAlpha($image, true); // Save imagepng($image, $settings['new_icon']); // save image as gif imagedestroy($image); } How could this be updated to allow some dithering (is that what it is called?) - the thing that smooths out an image to avoid pixelation around the edges? Minor question. 1) Is there any reason why imagecolorexact doesn't work in this function. When I use imagecolorexact nothing happens and the picture remains the same. I'm writing a <font color> to mysql for later retrieval but the colors don't make sense. It's posted and retrieved in PHP. If I put in <font color=\"#ff0000\">RED</font> it gets properly stored in the db (I can see it) but it gets retrieved and shows up green instead. I've tried doing the stripslashes() with addslashes(), tried <font color=\"#red\">RED</font> and <font color=\"red\">RED</font>.. no matter what config I try, I always get the word RED showing up green as if I had used <font color=\"#00ff00\">RED</font> instead (when I tried <font color=\"#00ff00\">RED</font> it shows up black. I give. What am I doing wrong? I know it's something dumb, but I can't find a similar issue with any searches. BTW, viewing the Source Code from the rendered page when it's posted shows it's properly tagged as red: color=\"#ff0000\" .Thanks. Hi guys, I would like to know on How to alternate table row colors in Php Mysql result? CSS or Html? Thanks Code: [Select] <? $result = mysql_query("SELECT * FROM tbl_sta WHERE fiesta_date > '$now' ORDER BY sta_date LIMIT 5"); echo "<table id='table1' cellspacing='1' cellpadding='3'> <tr> <th>Upcoming Fiesta</th> </tr>"; while($row = mysql_fetch_array($result)){ $date = date("l, F j ",strtotime($row["sta_date"])); echo "<tr>"; echo "<td><a href='fiestasd.php' style='font-size:12px;font-weight:bold;'>" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "</a> <br /> $date </td>"; echo "</tr>"; } echo "</table>"; ?> Thank you.. more power phpfreaks! Preferably using PHP, I'd like to create X number of colors based on X number of items and using a predefined color range. For example: ITEM VALUE 1 1,234,567,890 2 234,567,890 3 34,567,890 4 4,567,890 5 567,890 Color Range red = largest value green = medium value blue = smallest value Example Item 1 gets color red Item 2 gets whatever color naturally comes between red and green Item 3 gets color green Item 4 gets whatever color naturally comes between green and blue Item 5 gets color blue Requirements The code should be able to handle any number of items. 5 items was just an easy example. Some Thoughts - Number of items = number of colors - How to divide a color range into number of items? - Colors can be represented in decimal format: red=255,000,000 blue=000,000,255 - Can a formula be created, based on the color decimal format, to solve this problem? I think it's the math portion of the problem that I'm stuck on right now. Thanks for your help, Nick This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=321778.0 I'm trying to set different colors on rows of a table using an array, Problem is I cannot get it to work right, i'm not sure where to place my for loop so that it works right and generates a different color for different row. Code: [Select] $color = array(red,green,blue); while ($row = mysql_fetch_assoc($exec)) { echo '<tr>'; echo '<td>'.$row['brand_name'].'</td>'; echo '<td>'.$row['contact_name'].'</td>'; echo '<td>'.$row['contact_info'].'</td>'; echo '<td>'.$row['email'].'</td>'; echo '<td>'.$row['description'].'</td>'; echo '</tr>'; } I tried putting for loop only for tr, but it didnt work. Code: [Select] for ($i=0;$i<=count($color);$i++) { echo "<tr bgcolor=\"".$color[$i]."\">"; } I cannot put it within the while loop, it'll repeat the rows for all the colors. So where exactly do I place the for loop so that it works right? Question 1. Say I have a register form where a member registers with their full name but many people can have the same full name. What would be the best way to make the full name appear unique in the url(eg. website.com/member/johnsmith) for each member?
Question 2. I am not sure about other CMS but Shopify has this feature where you can change the colors of certain things on the website, in the backend. How is that achieved? I am a little lost on how you should connect css with php.
|