1

I have a global php variable $similarity; and I have this Bootstrap progress bar by the following code:

<div class="progress progress-striped active">
<div class="bar" style="width: 74%;"></div> 
</div>

The width (74% in the case) determines the amount by which the progress bar will look filed. What I want to do is to use the value of $similarity in place of that 74. So that progress bar will be filled according to the value of variable.

How can I do this?

3
  • Do you want the value to change as the user sits there staring at the screen, or do you want it to stay put at whatever value $similarity is when the user first requests the page? Commented Jan 5, 2013 at 7:09
  • if you wan to create multiple bar than you can use loop Commented Jan 5, 2013 at 7:10
  • Yes I want the the bar to be fixed when the user requests the page & gets whatever value is of $similarity. Th bar basically shows the similarity of two users entered by the user. Commented Jan 5, 2013 at 7:12

2 Answers 2

10

you can do this by

<div class="bar" style="width: <?php echo $similarity; ?>%;">

but make sure file extension is .php

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

Comments

2

Have you tried this?

<div class="progress progress-striped active">
<?php echo "<div class='bar' style='width: $similarity%;'></div>"; ?>
</div>

2 Comments

Thank you , it worked like charm ! How can I embed the above code inside my php tags. Since I want this progress bar to appear after the php has manipulated the value $similarity variable.
That would depend on how the rest of your PHP file looks, but this doesn't have to be in the same PHP tags as the part where you manipulate $similarity. Something like this should work just fine: <?php $similarity = 35; ... ?> <html> ... <div class="progress progress-striped active"> <?php echo "<div class='bar' style='width: $similarity%;'></div>"; ?> </div> ... </html>

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.