Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9023259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:43:10+00:00 2026-06-16T05:43:10+00:00

Despite the numerous attempts at trying to get this to work I’m stumped. I

  • 0

Despite the numerous attempts at trying to get this to work I’m stumped. I have explained in many other posts that I am very new to PHP and unfamiliar with the vast capabilities and know that I’ve almost got this to work but just can’t seem to make it happen. I’ve already had one very helpful person try to dumb it down for me [a link] https://stackoverflow.com/a/13872071/1880796 but now I just need someone to correct an error in my code to get it to work. I think there is something wrong at the end of the url because when I try to view the image and look at the url its all messed up so I don’t know what I’m doing wrong. I’ve double and triple checked all the math because it is so confusing but here is the result.php:

<?php
    $filename = "Results.txt";
    $lines = file($filename);

    $q1 = $_POST['q1']; // stores checked button value
    $q2 = $_POST['q2'];
    $q3 = $_POST['q3'];
    $q4 = $_POST['q4'];
    $q5 = $_POST['q5'];
    $q6 = $_POST['q6'];
    $q7 = $_POST['q7'];
    $q8 = $_POST['q8'];

    $qN = 1;  //question number

    $newLines = '';

    $total = array();

        foreach($lines as $line) {

            $line = trim($line);  //remove excess newlines etc.
            $lineArr = explode(',',$line);  //split line into array by commas
            $index = ${'q'.$qN}-1; //zero based
        if (isset($lineArr[$index])){
            $lineArr[$index]++;  //add to position by one vote.
            $total = array_sum($lineArr); //number of clicks 

            $newLines .= implode(',',$lineArr) . "\r\n"; //newLines contains numbers then also
        $qN++;
        }
    }
//write contents back to file.
file_put_contents($filename, $newLines);

//frequencies for each line without strings
$l[1] = explode(',',$lines[0]);
$l[2] = explode(',',$lines[1]);
$l[3] = explode(',',$lines[2]);
$l[4] = explode(',',$lines[3]);
$l[5] = explode(',',$lines[4]);
$l[6] = explode(',',$lines[5]);
$l[7] = explode(',',$lines[6]);
$l[8] = explode(',',$lines[7]);

//multiply each 
$result = array();
$values = array(1,2,3,4,5);
for($i=0;$i<count($l);$i++){
    for($j=0;$j<count($values);$j++){
    $result[$i+1][$j] = $l[$i+1][$j] * $values[$j];
    }
}
//calculate percentages

$p1 = (explode(',',$lines[0]));
$p2 = (explode(',',$lines[1]));
$p3 = (explode(',',$lines[2]));
$p4 = (explode(',',$lines[3]));
$p5 = (explode(',',$lines[4]));
$p6 = (explode(',',$lines[5]));
$p7 = (explode(',',$lines[6]));
$p8 = (explode(',',$lines[7]));

// calculate averages *****For some reason most recent frequency item updated is off by one, possibly bc not up to date yet???? figure out later!!!
$f1avg = round((array_sum($result[1])/($total-1)),2);
$f2avg = round((array_sum($result[2])/($total-1)),2);
$f3avg = round((array_sum($result[3])/($total-1)),2);
$f4avg = round((array_sum($result[4])/($total-1)),2);
$f5avg = round((array_sum($result[5])/($total-1)),2);
$f6avg = round((array_sum($result[6])/($total-1)),2);
$f7avg = round((array_sum($result[7])/($total-1)),2);
$f8avg = round((array_sum($result[8])/($total-1)),2);
//pie chart question 1 information
$p1f0 = round((($p1[0]/($total-1))*360),0);
$p1f1 = round((($p1[1]/($total-1))*360),0);
$p1f2 = round((($p1[2]/($total-1))*360),0);
$p1f3 = round((($p1[3]/($total-1))*360),0);
$p1f4 = round((($p1[4]/($total-1))*360),0);
//_____________$a0________$a1______________$a2___________________$a3__________________________$a4_______________
$pC1 = array(($p1f0),($p1f0+$p1f1),($p1f0+$p1f1+$p1f2),($p1f0+$p1f1+$p1f2+$p1f3),($p1f0+$p1f1+$p1f2+$p1f3+$p1f4));
print_r ($pC1);

And here is the pie chart script:

header("Content-type: image/png");

//create pie charts
$image=imagecreatetruecolor(51,51);
//_____________________colors____________________________
$my_colorA=imagecolorallocate($image,51,51,255);
$my_colorB=imagecolorallocate($image,100,150,215);
$my_colorC=imagecolorallocate($image,20,20,151);
$my_colorX=imagecolorallocate($image,216,216,255);


$red = imagecolorallocate($image, 255, 0, 0);
$orange = imagecolorallocate($image, 191, 64, 0);
$dark_yellow = imagecolorallocate($image, 128, 128, 0);
$dark_green = imagecolorallocate($image, 64, 191, 0);
$green = imagecolorallocate($image, 0, 255, 0);
//_______________________________________________________
imagefill($image,0,0,$my_colorX);

//__________________ , center,  w , h , st, end, clr  ,    type______
imagefilledarc($image,25,25, 50, 50,  0,  $a0, $red, IMG_ARC_PIE);
imagefilledarc($image,25,25, 50, 50, $a0,  $a1, $orange, IMG_ARC_PIE);
imagefilledarc($image,25,25, 50, 50, $a1, $a2, $dark_yellow , IMG_ARC_PIE);
imagefilledarc($image,25,25, 50, 50, $a2,  $a3, $dark_green, IMG_ARC_PIE);
imagefilledarc($image,25,25, 50, 50, $a3,  $a4, $green, IMG_ARC_PIE);
//___________________________________________________________________

imagepng($image);
imagedestroy($image);

I have no idea why it isn’t working but when I click view image i get this:
PieChart.php?a0=33&a1=66&a2=230&a3=263&a4=361/%3E%3C/td%3E%3Ctd%20style=

so yeah I don’t know what I’m doing wrong! Please help!

Oh and lastly this is what I’m putting into my html.

img src=\”PieChart.php?a0=”.$pC1[0].”&a1=”.$pC1[1]. “&a2=”.$pC1[2]. “&a3=”.$pC1[3].”&a4=”.$pC1[4].”/”

and yes I’m aware it needs the img tag and php and echo i just couldn’t post it in the form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:43:11+00:00Added an answer on June 16, 2026 at 5:43 am

    So the solution happened to be a syntax error of some form but for anyone coming looking for insight on the code above…

    1) Check the script by hard coding the input values and viewing the result.
    2) Check the parameters being passed from your calling function.

    After that, the code sample above is extremely similar to one you’ll find in the php manual.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code here that does not work despite me using
Despite some posts on this forum and others I cannot find something that tells
Despite many trials and errors, I cannot get the NumberTextBox widget to work. I
despite many tries I can't get the result that I would like to see
Despite reading lots of other posts regarding GIT and moved files I still struggle
Despite the plethora of URL routing posts, I have yet to reach enlightenment on
Despite reading many articles (some on this board) I am still scratching my head
Despite the fact that this is not good coding practice, I want a macro
Despite the title of this question, I am well aware that UIViewControllers cannot be
Despite that I’m a regular reader of this great forum, this is my first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.