I have my PHP code : from after the sql query...
$pieData = array();
}
while($row = mysqli_fetch_array($result))
{
$pieData[] = array('value' =>(int)$row['cnt'], 'color' => '#222222');
Now this works and is successful when I pass through json_encode(). I want to dynamically change the color.
From my database $result I access $row['Delaytype'] and want do something like this.
while($row = mysqli_fetch_array($result)){
if($row['Delaytype'] === "engineering"){
$pieData[] = array('value' =>(int)$row['cnt'], 'color' => '#222222');
}elseif($row['Delaytype'] === "something else"){
$pieData[] = array('value' =>(int)$row['cnt'], 'color' => '#888888');
}
The code works but it accepts the first true statement and carries on and all my colors have the same value and so does my resulting pie chart. I have tried a switch statement, if and attemtped to loop through the array but my understanding of this is limited.
Any help is really appreciated.
The table is called delays:
It is like
Delaytype | Delayhours
engineering | 3
engineering | 2
human error | 4
The SQL query :
"SELECT Delaytype, SUM('Delayhours') as cnt FROM delays GROUP BY
Delaytype;"
If I echo a table with
<tr><td>$row[delaytype]</td><td>$row[cnt]</td></tr> //forgive formatting
I will get from table above:
engineering 5
human error 4
strcasecmp also not working.
if i do if(1=1) it works so it is something to do with the comparison but it is correct the output is lowercase engineering but it is not seeing it when its tested?
I now have this working. Odd all I did was change "human error" to " human error " and "engineering" to " engineering ". I have looked at my html input values and found no leading spaces ? No idea why it works with the space. I am going to search through my code for a reason. Thanks for your help and other suggestions. strcasecmp works as well as without. I mark the awnser correct as everything you said did work... + it will show up awnsered and more likely get viewed for a similar problem. Thank for you help
engineeringandhuman error, then your comparison in theelseifbranch with"something else"doesn’t make any sense – it would lead to$pieDatabeing filled with only the records withengineering, the ones withhuman errorwould not be added to the array at all, since neither theifnor theelseifcondition match …