php - Division by zero with arrays -


alright, have array server query on game server holds information. made progress bar shows current amount of players. percentage of progress bar calculated this

<span style="width: ' . $data['gq_numplayers'] / $data['gq_maxplayers'] * 100 . '%;"></span> 

now, if server offline problems array empty , division 0/0 , causes error. how bypass/solve this?

perhaps use of if statement solution.

i.e.

if ($data['gq_maxplayers'] == 0) {    echo '<span style="width: 0%;"></span>'; } else {    echo '<span style="width: ' . $data['gq_numplayers'] / $data['gq_maxplayers'] * 100 . '%;"></span>'; } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -