/    Sign up×
Community /Pin to ProfileBookmark

The below code creates a table that shows a bar graph that with different colors the problem that I’m having is the data that creates each different color bars will not all have the same number of data entires but the sum of the percentages should equal 100% the bars are not keeping to the same length and are spilling over to another row any ideas how to fix this. the total length of all bars need to be the same

[code=php]
<?php
$query_get_survey_questions = “SELECT * FROM `survey`”;

$get_survey_questions = mysql_query($query_get_survey_questions)or die(mysql_error());

while ($survey_question = mysql_fetch_array($get_survey_questions)){ ?>
<?php

if($survey_question[“excellent”] != 0) {
$VoteExcellent = Round(($survey_question[“excellent”] / $survey_question[“total_votes”]) * 100) . “%”;
} else {
$VoteExcellent = 0 .”%”;
}
if($survey_question[“very_good”] != 0) {
$VoteVery_good = Round(($survey_question[“very_good”] / $survey_question[“total_votes”]) * 100) . “%”;
} else {
$VoteVery_good = 0 .”%”;
}
if($survey_question[“good”] != 0) {
$VoteGood = Round(($survey_question[“good”] / $survey_question[“total_votes”]) * 100) . “%”;
} else {
$VoteGood = 0 .”%”;
}
if($survey_question[“fair”] != 0) {
$VoteFair = Round(($survey_question[“fair”] / $survey_question[“total_votes”]) * 100) . “%”;
} else {
$VoteFair = 0 .”%”;
}
if($survey_question[“poor”] != 0) {
$VotePoor = Round(($survey_question[“poor”] / $survey_question[“total_votes”]) * 100) . “%”;
} else {
$VotePoor = 0 .”%”;
}

?>

<tr><td class=”left” style=”width:30%;”><?php echo $survey_question[‘question’] ;?></td>
<td colspan=”2″ class=”rightTwoColumn” style=”width:70%; height:50px;”><img src=”../images/redBar.gif” width=”<?=$VotePoor?>” height=”20″ title=”Poor: <?=$survey_question[“poor”]?> Total:<?=$survey_question[“total_votes”]?> Percent: <?= number_format($survey_question[“poor”] / $survey_question[“total_votes”]*100,2); ?>%” alt=”bar”><img src=”../images/purpleBar.gif” width=”<?=$VoteFair?>” height=”20″ title=”Fair: <?=$survey_question[“fair”]?> Total:<?=$survey_question[“total_votes”]?>Percent: <?= number_format($survey_question[“fair”] / $survey_question[“total_votes”]*100,2); ?>%” alt=”bar”><img src=”../images/yellowBar.gif” width=”<?=$VoteGood?>” height=”20″ title=”Good: <?=$survey_question[“good”]?> Total:<?=$survey_question[“total_votes”]?> Percent: <?= number_format($survey_question[“good”] / $survey_question[“total_votes”]*100,2); ?>%” alt=”bar”><img src=”../images/blueBar.gif” width=”<?=$VoteVery_good?>” height=”20″ title=”Very Good: <?=$survey_question[“very_good”]?> Total:<?=$survey_question[“total_votes”]?> Percent: <?= number_format($survey_question[“very_good”] / $survey_question[“total_votes”]*100,2); ?>% ” alt=”bar”><img src=”../images/greenBar.gif” width=”<?=$VotePoor?>” height=”20″ title=”Excellent: <?=$survey_question[“excellent”]?> Total:<?=$survey_question[“total_votes”]?> Percent: <?= number_format($survey_question[“excellent”] / $survey_question[“total_votes”]*100,2); ?>%” alt=”bar”>
</td>
</tr>
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@kprocauthorApr 14.2007 — forget it I figured it out there was an issue with my table data
Copy linkTweet thisAlerts:
@kprocauthorApr 14.2007 — there is still problem with this, if the sum of all the bars is more then 100 then it goes to the next row, how would I write a condition to insure that the sum does not exceed one hundred. It only ever going to be over by decimals

any thoughts
×

Success!

Help @kproc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...