1

I have a table that stores data. It has ratings for something that go 1-20. If something is a 1 then the page will load a bar with 5% width. Currently I have it so that the div uses style= and I just put the math in there.

<div class="bar" style="width:<?php $row["RATING"]*5 ?>%;">1/20</div>

That seems really messy but its the simplest way I could think of. Is there a cleaner more practical method?

2
  • It is pretty simple, that is my first thought how to do it :) Commented Aug 26, 2016 at 0:34
  • for percentage on bar/progressbar this is the easiest solution you can have Commented Aug 26, 2016 at 0:46

2 Answers 2

1

I think what you used is the better. If you define a class for each rating, then you have to create 20 classes. Keep things simple and focus on the idea of your application.

Sign up to request clarification or add additional context in comments.

1 Comment

I agree on the keeping it simple. Changed the wording on my answer to better reflect opinion. I would split it into css so you could benefit of changing things in the future easily if you wanted different colors per value for instance. And I try to avoid using inline style because in some cases for Dutch accessibility rules it's not allowed to use them. They require styles to be extracted into CSS files
0

It could work if you used class names to define the width. You could use the value as part of the class name.

<div class="bar width_<?php $row["RATING"] ?">1/20</div>

And define the used width in a CSS file. This will make it easier for changes in the future as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.