I am having a goal for the user that needs to hit and that user passed the goal I want it to show a different color. So right now I have total goals needed by having goals_needed * time_spent / day_length.
For example if the goal is 10, and user gets 11 points I want it to show a different color because he passed the goal. How would I get the result to show passed goal ?
I was thinking something like this
$color_performace = function($value, $goal) {
if($value < $goal)
return 'notenough';
elseif($value >$goal)
return 'awesome';
else
return 'enough';
};
and function
$total_goals_class = $color_performance($total_goals,round($goals_needed*$goal_multiplier));
It is not clear exactly what you are after but if you want to deal with getting things on the page to change colour you will need to output html & css.
So perhaps have something like:
$color_performace = function($value, $goal) {
if($value < $goal)
return '<p style="color: red;">notenough</p>';
elseif($value >$goal)
return '<p style="color: green;">awesome</p>';
else
return '<p style="color: yellow;">enough</p>';
};
That is a quick and dirty example to show the concept, I would probably change it to use classes and have the css set in a main file somewhere, and use hex codes for colours.
Related
I'm in trouble because i can't figured it out how to find my answer.
I'm creating a wordpress website and i have a search engine
I've created an option in my admin panel and code something to write in my option table, but my problem is now
firstly i grab my options from my database with
$mysynonymvalue = get_option( 'synonym-custom' );
I precise that it returne to me something like this ( mango, apple, banana)(this is an example of course)
My Url is something like this :
http://supserwebsite/wordpress/?sfid=2675&_sf_s=toto
Or this
http://superwebsite/wordpress/?sfid=2675&_sf_s=virtualisation cloud devops
so i've created a variable to catch the queries
$motsclefs3= $_GET['_sf_s'];
Now i want to compare the string $mysynonymvalueconvert with $motsclefs3 to find if it match so i write
if (strpos ($mysynonymvalue, $motsclefs3) ){
echo '<script >
$(document).ready(function(){
$(".vc-tabs-li:nth-child(2)").get(0).click();
});
</script>';
}
else{
echo '
<script >
$(document).ready(function(){
$(".vc-tabs-li").get(0).click();
});
</script>';
};
};
The solution seem to work correctly but i can't have the first result, it coompare indeed with all the results but not my first one.
And it doesn't work so fine because with only one letter it return a match ( for example 'a')
Any solution ?
Thanks
*provided url(s) are not accessible.
Solution:
Create a dictionary of option from db and then search the element which you are looking.
So far i move up a bit !So i came with this
I still have
$mysynonymvalue = get_option( 'synonym-custom' );
$mysynonymvalueconvert = preg_split('/[,]+/',$mysynonymvalue);
To grab my words from my database and to convert it into an array.
(the point of this is to get elements that were wrote by an user elsewhere on the admin panel of wordpress)
I also still have
$motsclefs3= $_GET['_sf_s'];
To grab my actual queries ( that will serv me to compare ). I precise that it return me a string. To be more specific, an URL like this (http://mywebsite/wordpress/?sfid=2675&_sf_s=examen) return me (in string) "examen".
Now my point is still to compare if
$motsclefs3;
is inside
$mysynonymvalueconvert
So i've created a "for" loop like this
for ($i = 0; $i <= count($mysynonymvalueconvert); $i++){
if(in_array($motsclefs3, $mysynonymvalueconvert)){
echo'yes';
break;
}
else{
echo 'no';
break;
};
};
But i'm still blocked, this return "yes" only if it match with the first element from
$mysynonymvalueconvert
So any ideas to help me ?
Thanks!
I'd like to display a div half the time. I thought about something like this :
Generate a number with : $nb = rand(0,1);
Then, for my div, I use a condition if:$nb == 0, it shows, if it is 1, it doesn't.
What do you think ?
Is there a easiest way because it looks a little untidy...
1. You should post such questions on [codereview.SE]
2. You can simplify your code to this:
if (rand(0,1)) {
//Show the div
}
0 will be converted to false, while 1 is being converted to true.
It's fine. If you're lookin for another way to do it use javascript :)
<script type="text/javascript">
if(Math.round(Math.random())==1) {
document.getElementById("myDiv").style.display='none';
} else {
document.getElementById("myDiv").style.display='block';
}
</script>
(gettimeofday()["usec"] % 2 == 1)
could be your randomization. gettimeofday()["usec"] is the current millisecond and we look at it whether it is odd or not.
I try show all the hours of the day in order 8, 9, 10 ... but to distinguish the hours that are in the database from the hours that are not. For instance, to give a different color. Can anyone help? (I am not a programmer and I am just learning php alone, so any I would appreciate any help, but explain it in a simple way, please)
This gives me the hours that I have in the database in blue. But I cannot to get hours that are not in the database and I cannot give them another color and the right position: 8, 9,10, 11...
$result = mysqli_query($con, 'SELECT * FROM consulta
WHERE professional=1
AND client=0');
while ($row = mysqli_fetch_array($result)) {
if ($row['hour']=='09:00:00') { echo '<p style="color:blue;">9</p>'; }
elseif ($row['hour']=='10:00:00') { echo '<p style="color:blue;">10</p>'; }
elseif ($row['hour']=='11:00:00') { echo '<p style="color:blue;">11</p>'; }
elseif ($row['hour']=='12:00:00') { echo '<p style="color:blue;">12</p>'; }
}
Here's some sudo code for you. Make an array with all the hours in it. Then iterate that array instead of the result from the database.
for ($i = 0; $i < 24; $i++) {
if(in_array("$i:00:00", $row)) {
// hour was found in the database
echo '<p style="color:blue;">'.$i.'</p>';
} else {
// hour was not found
echo '<p style="color:red;">'.$i.'</p>';
}
}
This way you're iterating over hours that are in the database. Just them. So if 11 is not in the database, if simply won't show. You need a different logic.
You need to iterate over all 24 hours and for each hour check if it is in the database, if so, apply styling, if not, render normally. And a hint, it might be easier to defince CSS classes instead of using inline styling (<p class="db">9</p> instead of <p style="color:blue;">9</p>, and of course, having the db class defined properly; that way you only need to change one rule instead of styling of each element in case you want to change something).
I am working on a PHP application and stumbled upon a problem on auto-highlighting.. I want to ask how to auto-highlight a cell of a table, whose data came from a database, after checking if the value is negative, 0, or positive, Red for negative, yellow for 0 and green for positive.
Please note that I have no experience regarding JavaScript or Ajax and rudimentary knowledge only on CSS. Thank you.
If needed, I can post any part of my code here.
It might be helpful for you:
function getSampleStatus($sampleid){
if($sampleid==1){
$color="#007334";
}elseif($sampleid==2){
$color="#3f96e8";
}elseif($sampleid==3){
$color="#ff9900";
}elseif($sampleid==4){
$color="#ff9770";
}
else{
$color="#ff0000";
}
$query='Select status from config where status_id='.$sampleid;
$this->_db->setQuery( $query );
$status =$this->_db->loadResult();
return "<span style='color:".$color.";padding-left:200px;'>".$status."</span>";
}
This function simply adds different colors depending on sample status.
For example:
For disapproved records, color red.
For Approved records, color green.
For Lab completed records, color yellow and so on..
Edit:
For Simplicity, try this:
$yourdatafromdatabase = 3; //which is either -ve, zero or positive
if($yourdatafromdatabase < 0){
$color="#FF0000"; //red for less than zero
}elseif($yourdatafromdatabase== 0){
$color="#FFFF00"; //yellow for zero
}
else{
$color="#00FF00"; //green for positive
}
echo "<span style=\"color: $color\"> <h1> Wow Color! </h1></span>";
?>
Working Demo:>>
just write css in table tag e.g
if ($value <0)
{echo "<td bgcolor=\"#FF0000\">$value</td>";}
when a user logs in, I want a input type text to be already filled with some pre-determined letter...
how can I make that possible?
You can do it in two ways:-
You can give control from the Admin area, so that the Administrator has the full control. This can be possible by providing a list drop down with all the recommended alphabets, in the Settings section of your Admin area, and let the Admin choose her preferred alphabet & store it in the database. Then you can retrieve it from the database & show it in the front-end when any user logs in.
When the user logs in, you can generate a random letter, using the PHP function "rand()".
One simple code snippet for the second solution will be:-
<?php
// This function considers both the cases for each of the letters.
function randLetter() {
$int = rand(0, 51);
$a_z = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$rand_letter = $a_z[$int];
return $rand_letter;
}
/**
* This function considers only one specific cases for each of the letters.
*/
function randSpecificCaseLetter($lower_case = TRUE) {
if ($lower_case) {
$letter = chr(rand(97, 122));
}
else {
$letter = chr(rand(65, 90));
}
return $letter;
}
?>
Hope it helps.