KarthikOnIT Posted January 1, 2011 Share Posted January 1, 2011 Hi Folks, I am newbie in PHP, we are designing a simple quiz game in PHP. I am trying to draw a horizontal progress bar in PHP.This is like a rectangle of length (10*1)and divided into ten equal parts of size(1*1). The quiz will have ten questions so the blocks will be filled with GREY colour initially, when the user answers the questions it will turn green or red depending on whether it's correct or not. I couldn't find a open source library which could do this. Should I use PHP GD and draw it? Thanks in advance. Karthik Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 1, 2011 Share Posted January 1, 2011 One way to do it would be to use variables and loops to control how many of each is displayed up to the total number needed. Pseudo-code: <?php $total_q = 10; $curr_q = 4; $remain = ( $total_q - $curr_q ); for( $i = 0; $i < $curr_q; $i++) { echo '<img src="green.jpg">'; } for( $r = 0; $r < $remain; $r++) { echo '<img src="grey.jpg">'; } ?> There might be better ways, but that's what came to mind immediately. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 1, 2011 Share Posted January 1, 2011 just take a solid image and strech it. <?php $qnum = (int)$_POST['qnum']; // for example 5 (50%) $total = 10; // Total questions if($qnum > $total) $qnum = $total; $width = ($qnum / $total) * 100; echo '<form action="" method="post">Question Number:<input type="text" name="qnum" /></form>'; echo '<div style="width:500px;border:solid 1px #000000;height:10px;">'; echo '<img src="blue.jpg" height="10px" width="'.$width.'%" />'; echo '</div>'; ?> You will get an error because I have strict mode on, but here is an example: http://96.42.108.211:3333/test.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.