php


change color according to max and min numbers


I want to change the calendar background color for day according to max and min values.
/* keep going with days.... */
for($list_day = 1; $list_day <= $days_in_month; $list_day++):
$check_day = checkDay($list_day, date("Y"), date("m"));
$red_start = $per_day_chu - 1;
$red_finish = $per_day_chu;
$yellow_start = $per_day_chu - 2;
$yellow_finish = $red_start;
$green_start = 0;
$green_finish = $yellow_start;
if($check_day > $red_start or $check_day == $red_start or $check_day >= $red_finish)
$calendar.= '<td class="calendar-day" style="background:#F00">';
else if($check_day > $yellow_start or $check_day == $yellow_start or $check_day >= $yellow_finish)
$calendar.= '<td class="calendar-day" style="background:#FFED00">';
else if($check_day > $green_start or $check_day == $green_start or $check_day <= $green_finish)
$calendar.= '<td class="calendar-day" style="background:#518F00">';
else
$calendar.= '<td class="calendar-day">';
/* add in the day number */
if($currentDayOfMonth == $list_day) {
$calendar.= '<div class="day-number"><font color="#F00">'.$list_day.'</font></div>';
}
else {
$calendar.= '<div class="day-number">'.$list_day.'</div>';
}
/** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/
$calendar.= str_repeat('<p>'.$check_day.'</p>',1);
$calendar.= '</td>';
if($running_day == 6):
$calendar.= '</tr>';
if(($day_counter+1) != $days_in_month):
$calendar.= '<tr class="calendar-row">';
endif;
$running_day = -1;
$days_in_this_week = 0;
endif;
$days_in_this_week++; $running_day++; $day_counter++;
endfor;
In the above code I have tried to display the 3 colors (red, yellow and green).
I will explain my concept in detail.
//Example 1
If $per_day_chu = 10 and $check_day = 0 to 6 then the background color for the day should be green and if $check_day = 7 or 8 then the color should be yellow and if $check_day = 9 or 10 the the color should be red.
//Example 2
If $per_day_chu = 8 and $check_day = 0 to 4 then the background color for the day should be green and if $check_day = 5 or 6 then the color should be yellow and if $check_day = 7 or 8 the the color should be red.
#per_day_chu and $check_day values will change dynamically. not a constant value.
I have tried using the above code. But the color not displaying correctly. Anyone please help me. Thankyou.
Code below did the trick :
<?php
$per_day_chu = 8;
for($i=0; $i <= $per_day_chu; $i++){
$first_color_count = $per_day_chu - 4; // set first color
$second_color_count = $per_day_chu - 2;
if($i <= $first_color_count)
$color = 'green';
else if($i <= $second_color_count)
$color = 'yellow';
else
$color = 'red';
echo 'Count: '.$i.' Color: '.$color.'<br>';
}
?>
Updated Code :
Instead of $i, you can use $check_day
$first_color_count = $per_day_chu - 4; // set first color
$second_color_count = $per_day_chu - 2;
if($check_day <= $first_color_count)
$color = 'green';
else if($check_day <= $second_color_count)
$color = 'yellow';
else
$color = 'red';

Related Links

Login Redirect in wordpress
Wildcard CORS with allowcredentials true
How do I create a background queue process in php to send sms and email to users
2 mysqli include files on one page
Error with PDO inserting into database [closed]
Php - Mail subscribe Form
Laravel 4 link_to with user id generates NotFoundHttpException
Get Specific Field
Magento - Conditionally Display Attribute Based on Product Category
Efficient way of adding keys to array
How to get the last auto-inserted SQL timestamp
Post the only modify input field php [closed]
How to deal with time zone in MySQL?
utf8 not converting string in PHP
Separating date and time from datetime format mysql
multiple child in nodes in php simplexml-displaying only first item

Categories

HOME
matrix
mpdf
freeradius
shinyapps
operating-system
haproxy
web2py
lvm
gentelella
openflow
hyperledger
drag-and-drop
fedora
mithril.js
gprs
cdi
timber
jquery-select2-4
angular4
squid
texas-instruments
async-await
l20n
office-ui-fabric
tfsbuild
significance
bazaar
backtracking
maven-surefire-plugin
liferay-6.2
batch-rename
background-color
marquee
bonita
windows2012
quick-nimble
cucumber-junit
image-optimization
payeezy
bootstrap-sass
xerces-c
ftp-server
nsuserdefaults
linq.js
assert
praat
export-to-pdf
uipickerview
get-event-store
jqgrid-asp.net
liteide
rm
sharpdx
msxml
emf-compare
adobe-reader
email-injection
bpms
boost-compute
jsonix
system.web.optimization
simian
jeasyui
management-studio-express
cortana
grinder
servicestack-bsd
opencyc
sqlbase
enaml
gql
artisan
erlog
signed
subview
html-escape-characters
sql-processor
image-rotation
squeezebox
assetic
illuminate-container
discovery
infinite
microformats
sly-scroller
html-frames
session-0-isolation
handshake
word-frequency
websphere-6.1
monocross
series-40
opends
dropshadow
uploading
quartz-core
servercontrol
drawimage
server-variables
nsconnection
django-pagination
formal-semantics
aptitude
pinax
urchin
spring-modules
rtti
database-cloning
suggestbox
regioninfo

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App