PHP - Changing Background Color In Lists Using Hex Codes Array In For Loop
I was trying to show different hex codes as background in a loop for each section of a list.
Here's what I done Code: [Select] $rgb; $rgb["c1"] = "ff4c54"; $rgb["c2"] = "ff764c"; $rgb["c3"] = "ffde4c"; $rgb["c3"] = "c7f25f"; $rgb["c4"] = "33c9f7"; $i=0; $pargs = array( 'numberposts' => 10,'orderby'=> 'comment_count', ); $myposts = get_posts( $pargs );$max_count=0; <ul> foreach( $myposts as $post ) : setup_postdata($post); <li style="width:300px;background-color:#<?php foreach($rgb as $color => $hex) { echo $hex[i]; $i++; } ?>"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> - </li> <?php endforeach; ?> </ul> Ending up with just the white background.. and no change in the background colors. Kindly help Similar Tutorialsi dont know if this is strictly a php problem, anyway... i have a query which returns rows from my database and then displays them in a table.. but what i want to know is how do i then get the bg color to change? Code: [Select] <?php if ($_GET['quantity'] == null) { $_GET['quantity'] = 20; } if (mysql_numrows($gold) != 0) { ?> <table width="100%"> <tr> <td>Seller</td> <td>Sellers Average Delivery Speed</td> <td>Price (per <?=$_GET['quantity'];?>M)</td> <td></td> </tr> <?php while ($row = mysql_fetch_array($gold)) { $seller_id = $row['seller_id']; $price_unit = $row['price_unit']; $order_id = $row['id']; $user = mysql_query("SELECT * FROM users WHERE id='$seller_id'"); $user = mysql_fetch_array($user); $average_time = ($user['transcation_time'] / $user['transaction_amount']); ?> <tr> <td><center><a href="profile.php?id=<?=$seller_id;?>"><?= $user['username']; ?></a></center></td> <td><center><?php if ($user['transcation_amount'] <= 4){echo "Now Timing";} if ($user['transcation_amount'] >= 5){ echo $average_time; }?></center></td> <td><center>$<?= $price_unit; ?></center></td> <td><center><a href="offer/checkout.php?order_id=<?=$order_id;?>"><img src="image/buttons/checkout.gif" width="120" height="20"></a> </center></td> </tr> <?php } } ?> </table> I am letting users select there color code option for text-shadow for there username I am storing them into a field called "color" HEX exaMPLE: FF6633,AA3633 First is the background color, 2nd is the foreground. (then i'll explode them) Is there a PHP function that let's me validate the input so it's HEX ONLY? I will be db escaping it and intval it too. I'm trying to create a part of a script where by the system will generate a sku code and loop through out to see if this exists in the database, if the sku does the script adds one too the code so 001 will turn to 002 then it will keep looping until it finds a SKU that isn't in the database.
However I can get the script to keep generating the new SKU codes but it will only test the first SKU code so the loop will keep going if it exists.
$number=001; if(isset($_POST['submit'])){ $product = $_POST['product']; $brand = $_POST['brand']; $description = $_POST['description']; $contruct=strtoupper($product."-".$brand."-".$description); $number=sprintf("%03s",$number); $check_for=$contruct."-".$number; $query=$cc_db->query("SELECT `sku` FROM `product` WHERE `sku`='".$check_for."'"); $fetch=$cc_db->fetch_object($query); $checking=$cc_db->num_rows($query); while($checking > 0){ echo"$check_for is there : $checking rows : $fetch->sku<br>"; $number=$number+1; $number=sprintf("%03s",$number); $check_for=$contruct."-".$number; } echo $checking; echo $check_for; } Hi, I need help to create a list like this with data from a database im having trouble doing so i have a table called company with 5 fields (installer, assessor, provider, trainer, other) if for example installer in the filed list = 1 then add to list else dont and see if assessor needs added if = 1 add then close list and see if provider = 1 if it does'tn then ask next. <ul> <li>Item 1</li> <li>Item 2</li> </ul> <ul> <li>Item 3</li> <li>Item 4</li> </ul> i have a list of check boxes im ordering it according to Amenity name ASC im floating 2 divs (columns)side by side how can i get the list to echo it according to ABC : like this::? A D B E C F Code: [Select] <?php echo '<div style="height:800px;" />'; foreach($amens as $amen) { echo '<div style="float:left;padding-left: 2px;width:200px;"><input onclick="changedata(this)" type="checkbox" id="mm'.$amen['Amen_ID'].'" value="'.$amen['Amenity'].'" '.checkAmenity($id, $amen['Amenity']).' /><label style="padding-left:3px;" for="mm'.$amen['Amen_ID'].'">'.$amen['Amenity'].'</label></div>'; } echo '</div>'; ?> I have a system on my forum where the admin can change the colors of certain elements. Take the divs with and id of header for example. They can change the color of these and the value is added to the database. Then in my initialize file which is always called with every page, i set the color for the headers to the database value: $color['headers'] = $row['headers']; but then i have to go to every header div and add <div id="header" style="color:'.$color['headers'].'";> this means doing this for every header div and i dont just allow them to change the font color, but also background color and borders. Would there be a better way of doing this without adding these variables to the style attr of the element? when i view the code in firebug there are alot of style attr with all of these variables and it makes the code look a mess, and also makes it tedious work to add these variables to every element. Thanks Hey Guys! First off, great looking resource, looks like tons of helpful people here. Secondly, I'll upload the file I need help with. Basically I'm looking to change the color of certain words that don't show up well now that I changed the background color.. but there are so many things in this script I can't figure out which one to change. I'm trying to change the words across the top that are in grey, to a lighter color. The site is laughing2myself.com if you need to have a look THANKS! Any help would be greatly appreciated! Hi people I'm trying to show all my data in my database, and I'm trying to make the font color change after 7 days to yellow and after 14 days it should show up red. But it does not work, could someone see any error in the code? It turns up green all the time.. Code: [Select] while($row = mysql_fetch_array($result)) { $postTime = $row['date']; $thisTime = time(); $timeDiff = $thisTime-$postTime; if($timeDiff <= 604800) { // Less than 7 days[60*60*24*7] $color = '#D1180A'; } else if($timeDiff > 604800 && $timeDiff <= 1209600) { // Greater than 7 days[60*60*24*7], less than 14 days[60*60*24*14] $color = '#D1B30A'; } else if($timeDiff > 1209600) { // Greater than 14 days[60*60*24*14] $color = '#08C90F'; } echo '<tr style="color: '.$color.';">'; echo '<td>'. $row['id'] .'</td>'; echo '<td>'. date("d.m.y", strtotime($row["date"])) .' </td>'; echo '<td><a href="detaljer.php?view='. $row['id'] .'">'. $row['Navn'] .'</a></td>'; echo '<td>'. $row['Telefon'] .'</td>'; echo '<td>'. $row['Emne'] .'</td>'; echo '</tr>'; } echo '</table>'; I am trying to write some code for my website. I pull information out of a database using a while loop. What am I trying to figure out is how to change some of the information. Some of the information used by the database is not there. It is not there cause I lost it and don't know what to put in place. The missing information is a Date Field. In the database if the field is blank it displays 0000-00-00. On the page it displays 01-01-1970. What I want to do is when the date is 01-01-1970 it actually shows N/A. How would I go about doing this? This is the code that I am using to draw the information from the database. Code: [Select] if ($year == 'other') { $sqlC = "SELECT * FROM `ttmautos` WHERE YEAR(date_return) < 2008 ORDER BY `date_return` DESC"; $resultC = mysql_query($sqlC) or die(mysql_error()); if (mysql_num_rows($resultC) == 0) { echo "There currently are no signatures in the database from $year"; } else { $autographs = "<table id='ttm'>\n"; $autographs .= "<tr class='first'><th>Player</th><th>Date Sent</th><th>Date Returned</th><th>Item Signed</th><th>Project</th></tr>\n"; $autographs .= "<tr><td id=\"blank\"></td><td id=\"blank\"></td><td id=\"blank\"></td><td id=\"blank\"></td><td id=\"blank\"></td></tr>\n"; while ($row = mysql_fetch_assoc($resultC)) { $category = $row['category']; $fname = $row['f_name']; $lname = $row['l_name']; $dsent = date('m-d-Y', strtotime($row['date_sent'])); $dreturn = date('m-d-Y', strtotime($row['date_return'])); $ireturn = $row['item_return']; $project = $row['project']; $autographs .= "<tr><td class=\"auto_cell\">$fname $lname</td>"; $autographs .= "<td class=\"auto_cell\">$dsent</td>"; $autographs .= "<td class=\"auto_cell\">$dreturn</td>"; $autographs .= "<td class=\"auto_cell\"><a href=\"signatures.php?c=$category&l=$lname&f=$fname\">$ireturn</a></td>"; $autographs .= "<td class=\"auto_cell\"><a href='projects/$project.php'>$project</a></td></tr>\n"; } $autographs .= "</table>"; echo "$autographs"; } } } I hope that I have given enough information to help me out with this issue. Hi Guys, Theres probably a really simple way to do this, but i haven't touched php in a wee while lol this code: foreach ($menu as $elem) { $selected1 = ''; $selected2 = ''; if ($elem['system_name'] == $this->system_name) { $selected1 = '<b>'; $selected2 = '</b>'; } if ($elem['system_name'] != 'home-content') { $elem['system_name'] = $elem['system_name'] . '.html'; } else { $elem['system_name'] = ''; } printf('<li class="%s">%s<a href="%s/%s">%s</a>%s</li>', $elem['li_class'], $selected1, ROOT, $elem['system_name'], $elem['title'], $selected2); } ?> Prints out the navigation on one of my sites, when the code loops through the menu i want to change one of the href targets for example: if (loop through menu) { if (page returned for example users page) { <a href="[b]CHANGE THIS TO SOMETHING.html[/b]"> } } So i only need to change one of the hrefs not all of them any help would be appreciated thanks guys Graham I have a sequential multidimensional array with many outer rows where all the inner arrays have the same number of elements as another sequential array which represents metadata of the first array's inner arrrays. $keys: ["time","system1_typeA","system2_typeA","system1_typeB","system3_typeC","system2_typeB","system1_typeC"] $arrayValues: [ ["2020-06-27 07:40:06",2.16,9.25,9.44,7.76,5.43,1.12], ["2020-06-27 07:40:23",2.66,8.93,4.31,6.59,8.44,3.42], ["2020-06-27 07:41:24",8.71,2.78,8.92,6.58,3.65,4.38], ["2020-06-27 07:41:58",1.86,6.36,2.65,3.99,7.25,3.32], ["2020-06-27 07:42:33",8.71,3.66,8.82,8.54,8.22,4.51] ]
{ "time": ["2020-06-27 07:40:06", "2020-06-27 07:40:23", "2020-06-27 07:41:24", "2020-06-27 07:41:58", "2020-06-27 07:42:33"], "system1": { "typeA": [2.16, 2.66, 8.71, 1.86, 8.71], "typeB": [9.44, 4.31, 8.92, 2.65, 8.82], "typeC": [1.12, 3.42, 4.38, 3.32, 4.51] }, "system2": { "typeA": [9.25, 8.93, 2.78, 6.36, 3.66], "typeB": [5.43, 8.44, 3.65, 7.25, 8.22] }, "system3": { "typeC": [7.76, 6.59, 6.58, 3.99, 8.54] } } Is there much faster way to do so than the following? I would like to use a built in function like array_combine() if possible, but grouping by system and type creates an issue. function transform(array $keys, array $arrayValues):array { $map=[]; foreach ($keys as $key) { $map[] = explode('_',$key); } $count=count($keys); $newValues=[]; foreach ($arrayValues as $i=>$arrayValue) { $newValues['time'][]=$arrayValue[0]; for ($i = 1; $i < $count; $i++) { $newValues[$map[$i][0]][$map[$i][1]][]=$arrayValue[$i]; } } return $newValues; }
I want to change the background to a light gray if the value of the $UOMPDROPSEQUENCE field is an odd number.
What would be the best way to do this please keep in mind I am very new to programming and PHP Thanks
Below is a snippet of my code.
$result =odbc_exec($connect,$sql); if(!$result){ exit("Error in SQL"); } echo "<table><tr>"; echo "<th>Drop</th>"; echo "<th>Name</th>"; echo "<th>Note</th>"; echo "<th>PO</th>"; echo "<th>Box_count</th>"; echo "<th>Cubes</th>"; echo "<th>ADDRESSLINE</th>"; echo "<th>ADDRESS2</th>"; echo "<th>CITY</th>"; echo "<th>STATE</th>"; echo "<th>ZIP</th>"; echo "<th>Order_ID</th>"; echo "<th> Phone </th>"; while (odbc_fetch_row($result)) { $UOMPDROPSEQUENCE=odbc_result($result,"UOMPDROPSEQUENCE"); $cmlName=odbc_result($result,"cmlName"); $UCMLSTOREHOURSTXT=odbc_result($result,"UCMLSTOREHOURSTXT"); $ompCustomerPO=odbc_result($result,"ompCustomerPO"); $UOMPTOTALBOXCOUNT=odbc_result($result,"UOMPTOTALBOXCOUNT"); $UOMPVOLUMETOTAL=odbc_result($result,"UOMPVOLUMETOTAL"); $CMLADDRESSLINE1=odbc_result($result,"CMLADDRESSLINE1"); $CMLADDRESSLINE2=odbc_result($result,"CMLADDRESSLINE2"); $CMLCITY=odbc_result($result,"CMLCITY"); $CMLSTATE=odbc_result($result,"CMLSTATE"); $CMLPOSTCODE=odbc_result($result,"CMLPOSTCODE"); $ompSalesOrderID=odbc_result($result,"ompSalesOrderID"); $cmlPhoneNumber=odbc_result($result,"cmlPhoneNumber"); echo "<tr><td>$UOMPDROPSEQUENCE </td>"; echo "<td align='center'>$cmlPhoneNumber</td>"; echo "<td align='center'>$UCMLSTOREHOURSTXT</td>"; echo "<td align='center'>$ompCustomerPO</td>"; echo "<td align='center'>$UOMPTOTALBOXCOUNT</td>"; echo "<td align='center'>$UOMPVOLUMETOTAL</td>"; echo "<td align='center'>$CMLADDRESSLINE1</td>"; echo "<td align='center'>$CMLADDRESSLINE2</td>"; echo "<td align='center'>$CMLCITY</td>"; echo "<td align='center'>$CMLSTATE</td>"; echo "<td align='center'>$CMLPOSTCODE</td>"; echo "<td align='center'>$ompSalesOrderID</td>"; echo "<td align='center'> $cmlPhoneNumber</td></tr>"; } odbc_close($connect); I have got a code working to generate a menu from a mysql table, but I wan't to know if it is possible to have the background colour change to a third option when active. I have 1 background colour for 'off', one for mouseover, but can't figure out how to tell it what they current page is so that it will use a different css class value, as the page obviously reloads after the link is clicked. Is it possible (hope my explanation makes some sence!) My code: At the moment mainNav a: and mainNav a:hover work ok but what I want is a mainNav a:active to stay on after the page has loaded Code: [Select] <?php //function to nest the menu tree function nest_child(&$nodes, $current) { if (!isset($nodes) || count($nodes) < 1) { return; } foreach ($nodes as $id => $item) { if ($current['parentdocid'] == $id) { if (!isset($item['children'])) { $item['children'] = array(); } array_push($item['children'], $current); $nodes[$id] = $item; } else { nest_child($item['children'], $current); } } } //functions to display the tree and expand as appropriate function menu_display($nodes, $display_id) { if (!isset($display_id) || ($display_id == '')) { $display_id = 1; } $result = node_display( array( 'doc_id' => 1, 'children' => $nodes ), $display_id ); return $result[1]; } function node_display($node, $display_id) { global $ROOT; $found = false; $text = ''; if (isset($node[children])) { foreach ($node[children] as $id => $child) { $text .= "<li class='mainNav'><a href='$ROOT/index.php?doc_id=$child[doc_id]'>$child[doc_name]</a>"; $result = node_display($child, $display_id); if ($result[0]) { $found = true; $text .= "<ol>$result[1]</ol>"; } if ($child[doc_id] == $display_id) { $found = true; if (isset($child[children])) { $text .= "<ol>"; foreach ($child[children] as $id => $grandchild) { $text .= "<li class='mainNav'><a href='$ROOT/index.php?doc_id=$grandchild[doc_id]'>$grandchild[doc_name]</a>"; } $text .= "</ol>"; } } $text .= "</li>"; } } if ((!$found) && ($display_id != 1)) { $text = ''; } return array($found, $text); } ?> <ul class="menu"> <?php //retrieve all the menu elements $result = mysql_query('SELECT * FROM docs ORDER BY doc_order ASC'); $menu = array(); while ($row = mysql_fetch_assoc($result)) { $menu[$row['doc_id']] = $row; } //nest the elements foreach ($menu as $id => $item) { if ($item['parentdocid'] != 1) { nest_child($menu, $item); unset($menu[$id]); } } //display the tree print menu_display($menu, $doc_id); ?> </ul> how can i set the color of a table background depending on what a variable is in my database? I currently have a table which echos data from my database, but i want the background too be a color depending on the value of a variable called 'status' (there are 3 variations) the variations are; order placed, processing and complete so for example: Code: [Select] if (status == placed) { background would be red } Code: [Select] if (status == processing) { background would be orange } Code: [Select] if (status == complete) { background would be green } appreciate any help. thank you. I need a button in php to change my background color every 5 presses with a random one, every five presses the color have to change once and need to stay for the next 5 presses. here is my code <head>
<title>click 5 times</title> Hi, I've making a script that's almost a todo list, and i want to have 3 colors to the posts. Post under 7 days old should be green, and thoose older then 7 days yellow and over 14 days should be red. How could i do that? Every post i timestamp when stored in my MYSQL table. Here is my code: Code: [Select] <?php $servername='localhost'; $dbusername='root'; $dbpassword=''; $dbname='store'; connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } $result = mysql_query("SELECT * FROM henvendelser ORDER by id desc ") or die(mysql_error()); echo "<table cellspacing='12px' cellpaddomg='5px' align='center'>"; echo "<tr> <th>ID</th> <th> Opprettet </th> <th>Navn</th> <th>Telefon</th> <th>Emne</th> </tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr> <td>"; echo $row['id']; echo "</td> <td>"; echo date("d.m.y", strtotime($row["date"])); echo "</td> <td>"; echo "<a href=\"detaljer.php?view=$row[id]\">$row[Navn]</a>"; echo "</td> <td>"; echo $row['Telefon']; echo "</td> <td>"; echo $row['Emne']; echo "</td> </tr>"; } echo "</table>"; ?> Hi, I've got the follow array: Query: Code: [Select] SELECT concat(monthname(gl_date),", ",year(gl_date)) as "monthYear", concat(DATE_FORMAT(gl_date,"%d-%m-%Y"),", ",gl_venue) as "dateVenue", DATE_FORMAT(gl_date,"%d-%m-%Y")as "date", gl_venue as "venue", gl_city as "city", gl_postcode as "postcode", gl_text as "description", concat(DAYOFMONTH(gl_date), MONTHNAME(gl_date),".png") AS "imageName" FROM tg_gig_list where gl_date >= curdate() and gl_publish = 1 order by gl_date Array: Code: [Select] $array = array(); $array['gigs'] = array(); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $array['gigs'][] =$row; } $output = json_encode($array); This returns JSON like this: - Code: [Select] { "gigs": [ { "monthYear": "May, 2011", "dateVenue": "14-05-2011, Queen Victoria hall", "date": "14-05-2011", "venue": "Queen Victoria hall", "city": "Oundle", "postcode": "PE8 4EJ", "description": "", "imageName": "14May.png" }, { "monthYear": "May, 2011", "dateVenue": "19-05-2011, O'Neill's", "date": "19-05-2011", "venue": "O'Neill's", "city": "Peterborough", "postcode": "PE1 1SQ", "description": "This one is another outing for Jason and Darren's acoustic duo, the pair will be playing a selection of their favourite songs as well as some tunes from the guards set.<br \/>\r\n<br \/>\r\n19:00 to 21:00", "imageName": "19May.png" }, {.......next record I'd like the data to be arranged by the 'monthYear' field....something like this... Code: [Select] { "gigs": [ "monthYear": "May, 2011" { "monthYear": "May, 2011", "dateVenue": "14-05-2011, Queen Victoria hall", "date": "14-05-2011", "venue": "Queen Victoria hall", "city": "Oundle", "postcode": "PE8 4EJ", "description": "", "imageName": "14May.png" }, {......all gigs for 'May, 2011' } "monthYear": "June, 2011" {....records for 'June, 2011' so 'gigs'=>'monthYear'=>'other records' I've tried all sorts of combinations of putting the '$row['monthYear']' field in different places in the array, but I seem to loose data by doing so for some reason. any input greatly appreciated. Darren This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=352099.0 Good Day, I am trying to create a table where the background color alternates between colors based on the category. The query sorts the category in alphabetical order. So for every category that is the same the background color will be the same. When the category changes, the background color changes. Alternating between two colors will be fine. I am not even sure where to begin on the sort of loop. So I want php to create a table like below: <table width="300" border="1" cellspacing="0" cellpadding="0"> <tr bgcolor="#CCCCCC"> <td width="117">Category 1</td> <td width="177">Excetion data</td> </tr> <tr bgcolor="#CCCCCC"> <td>Category 1</td> <td>Excetion data</td> </tr> <tr bgcolor="#CCCCCC"> <td>Category 1</td> <td>Excetion data</td> </tr> <tr bgcolor="#FFFFCC"> <td>Category 2</td> <td>Excetion data</td> </tr> <tr bgcolor="#FFFFCC"> <td>Category 2</td> <td>Excetion data</td> </tr> <tr> <td bgcolor="#CCCCCC">Category 3</td> <td bgcolor="#CCCCCC">Excetion data</td> </tr> <tr> <td bgcolor="#CCCCCC">Category 3</td> <td bgcolor="#CCCCCC">Excetion data</td> </tr> <tr> <td bgcolor="#CCCCCC">Categor 3</td> <td bgcolor="#CCCCCC">Excetion data</td> </tr> </table> Hi Just learning PHP and I'm struggling with a very simple problem. I'm playing around with arrays as i figure they're one of the most important things to know inside out but I can't work out how to change the value of an array element via a loop. I can obviously do it if I just directly write $cars[2] = "test" but not having any luck with the loop. I've tried using "foreach" and passing a new value to the $value variable but when i do a print_r the values in the array are unchanged. Code: [Select] $cars[0]="Saab"; $cars[1]="Volvo"; $cars[2]="BMW"; $cars[3]="Toyota"; foreach ($cars as $key => $value) { $value = "TEST"; echo $key . " " . $value . "<br />"; } print_r($cars) I then tried using a for loop Code: [Select] for ($i=0; $i <= count($cars); $i++) { echo $cars[$i]; $cars[$i] = "2"; } But this code just threw up a fatal error as follows: "Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 16 bytes) in /home/zzzzzzzz/public_html/php_testing/arrays.php on line 27" So would someone be kind enough to explain where i'm going wrong and why i get the fatal error on the second for loop. Thanks Drongo |