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

  • Home
  • SEARCH
  • 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 8282377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:21:03+00:00 2026-06-08T10:21:03+00:00

I have created a survey system using php and mysql. I have a table

  • 0

I have created a survey system using php and mysql. I have a table of answers called “answer” which stores all the responses submitted by users. I have created a script to generate a google graph to show statistics on 2 questions at a time. This script seems to work sometimes with very little response time and sometimes it takes forever and even returns an internal server error (i think because its taking to long to get the results but im not sure)

Here is the php script

<?
// DB CONFIG FILE
require("../db/config.inc.php");
// DB CLASS FILE
require("../db/Database.class.php");
// CREATE THE $DB OBJECT
$db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
// DB CONNECTION
$db->connect();


error_reporting(-1);

// GET THE SERVER ID VIA POST
$sID = 1342625918; // HARD NUMBER FOR TESTING

// GET THE QUESTION IDS VIA POST
$question1 = 5; // HARD NUMBER FOR TESTING
$question2 = 17; // HARD NUMBER FOR TESTING

//GET THE NAME OF THE SURVEY
$sql = "SELECT * FROM survey WHERE sID = '$sID'";
$rows = $db->query($sql);
while ($record = $db->fetch_array($rows)) {
$sName = $record["sName"];
}

//GET QUESTION ONE
$sql = "SELECT * FROM questions WHERE qID = '$question1'";
$rows = $db->query($sql);
while ($record = $db->fetch_array($rows)) {
$q1Text = $record["qName"];
}

//GET QUESTION TWO
$sql = "SELECT * FROM questions WHERE qID = '$question2'";
$rows = $db->query($sql);
while ($record = $db->fetch_array($rows)) {
$q2Text = $record["qName"];
}

//THIS GETS THE NAMES FOR THE GOOGLE GRAPH
$sql006 = "SELECT * from survey_selected_question, survey_selected_question_selected_option, options WHERE survey_selected_question.qID = '$question1' AND survey_selected_question_selected_option.ssqID = survey_selected_question.ssqID AND options.oID = survey_selected_question_selected_option.oID AND survey_selected_question.sID = '$sID'";
$rows006 = $db->query($sql006);
$numRes006 = $db->affected_rows;
$names = "";
while ($record006 = $db->fetch_array($rows006)) {
$names .= "'".$record006["oName"]."',";
}
// CLEAN UP THE NAMES VAR
$names = substr($names, 0, -1);


// START FUNCTION FOO
function foo($answer1, $answer2, $sID){

// CREATE THE DB OBJECT
$dbOne = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
// DB CONNECTION
$dbOne->connect();

$returnVal = 0;

//GET THE DISTINCT SUBMISSIONS FROM THE ANSWERS TABLE FOR THIS SPECIFIC SURVEY
$sql0 = "SELECT DISTINCT(submissionID) FROM answer WHERE sID = '$sID'";
$rows0 = $dbOne->query($sql0);

while ($record0 = $dbOne->fetch_array($rows0)) {

$submissionID = $record0["submissionID"];

// SELECT SUBMISSIONS WHERE ANSWER = PASSED ANSWER 1 or 2
$sql01 = "SELECT * from answer WHERE submissionID = '$submissionID' AND (answer = '$answer1' OR answer = '$answer2')";
$rows01 = $dbOne->query($sql01);
$numRes = $dbOne->affected_rows;

if($numRes=='2'){

$returnVal = $returnVal + 1;

}
}
return $returnVal;

$dbOne->close();
}
//END FUNCTION FOO

// START FUNCTION FOO2
function foo2($oID, $sID, $question1){

// CREATE THE DB OBJECT
$dbTwo = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
// DB CONNECTION
$dbTwo->connect();

// GET OPTION IDS AND BUILD AN OUTWARD STRING FOR GOOGLE GRAPH OF RESULTS
$sql2 = "SELECT * from survey_selected_question, survey_selected_question_selected_option, options WHERE survey_selected_question.qID = '$question1' AND survey_selected_question_selected_option.ssqID = survey_selected_question.ssqID AND options.oID = survey_selected_question_selected_option.oID AND survey_selected_question.sID = '$sID'";
$rows2 = $dbTwo->query($sql2);
$returnVal2 = "";
while ($record2 = $dbTwo->fetch_array($rows2)) {

$returnVal2 .= "".foo($record2["oID"], $oID, $sID).",";
}
//END FUNCTION FOO2

// CLEAN UP THE RETURNVAL2
substr($returnVal2, 0, -1);

// RETURN THE VAL HERE
return $returnVal2;
$dbTwo->close();
}

// START BUILDING THE google Array
$sql003 = "SELECT * from survey_selected_question, survey_selected_question_selected_option, options WHERE survey_selected_question.qID = '$question2' AND survey_selected_question_selected_option.ssqID = survey_selected_question.ssqID AND options.oID = survey_selected_question_selected_option.oID AND survey_selected_question.sID = '$sID'";
$rows003 = $db->query($sql003);
$numRes2 = $db->affected_rows;
$googleArray = "";
while ($record003 = $db->fetch_array($rows003)) {

$googleArray .= "['".$record003["oName"]."',".foo2($record003["oID"], $sID, $question1)."],";
?>
<?

}

// CLEAN UP THE GOOGLE ARRAY
$googleArray = substr($googleArray, 0, -1);

?>
<!DOCTYPE HTML>
<html>
<head>
<meta name = "viewport" content = "width = device-width">
<meta name = "viewport" content = "initial-scale = 1.0, user-scalable = no">
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
        ['Name',<?= $names; ?>],
        <?= $googleArray; ?>
]);

        var options = {
          title: 'Line graph for question "<?= $q1Text; ?>" against question "<?= $q2Text; ?>"'
          , colors:['#5D0F99','#2F543B','#BD2115','#D67314','#F92985','#0D85C7','#000D9C','#D9A5F6', '#27E80C', '#725F53']
        };

        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
<style>
div#wrapper {
max-width: 700px;
overflow:hidden;
background:#eee;
margin: 0 auto;
padding: 8px 8px 8px 8px;
border:1px solid black;
}

a{
    color:#000;

}

input.goback {
background-color: #ccc;
border: 1px outset #000;
color: #000;
padding: 4px;
margin-left: 2px;
}

</style>
</head>
<body>
<div id="wrapper">
<h1><?= $sName; ?></h1>

<form method="post" action="main.php">
<p>Show me average(s) on 
  <select name="oID">
  <?
//GET QUESTION ONE
$sql004 = "SELECT * from survey_selected_question, survey_selected_question_selected_option, options WHERE survey_selected_question.qID = '$question1' AND survey_selected_question_selected_option.ssqID = survey_selected_question.ssqID AND options.oID = survey_selected_question_selected_option.oID AND survey_selected_question.sID = '$sID'";
$rows004 = $db->query($sql004);

while ($record004 = $db->fetch_array($rows004)) {
?>
  <option value="<?= $record004["oID"]; ?>"><?= $record004["oName"]; ?></option>
<?
}
?>
</select>

with these survey type(s): 
<select name="types">
<option value="0">All</option>
<?
//GET THIS SURVEYS TYPES
$sql005 = "SELECT * from survey_types, survey_selected_types WHERE survey_selected_types.sID = '$sID' AND survey_selected_types.stID = survey_types.stID";
$rows005 = $db->query($sql005);

while ($record005 = $db->fetch_array($rows005)) {
?>
<option value="<?= $record005["stID"]; ?>"><?= $record005["stName"]; ?></option>
<?
}
?>
</select>

over a 12 month period.

<input type="hidden" name="sID" value="<?= $sID; ?>">
<input type="hidden" name="question1" value="<?= $question1; ?>">
<input type="hidden" name="edit" value="average">
<input type="hidden" name="question2" value="<?= $question2; ?>">
<input type="submit" name="submit" value="Go" class="goback">
</p>
</form>

<div id="chart_div" style="width: 675px; height: 500px;"></div>
<form method="post" action="main.php">
<p>
<input type="hidden" name="edit" value="survey">
<input type="hidden" name="sID" value="<?= $sID; ?>">
<input type="submit" value="Back To Statistics" class="goback">
</p>
</form>
</div>
</body>
</html>
<?
$db->close();
?>

and here is the html it outputs (if and when it works… like i said sometimes it returns fairly quickly and sometimes not at all with an internal server error)

<!DOCTYPE HTML>
<html>
<head>
<meta name = "viewport" content = "width = device-width">
<meta name = "viewport" content = "initial-scale = 1.0, user-scalable = no">
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
        ['Name','None','$1 - $50','$51 - $200','Over $200'],
        ['Yes',85,100,87,82,],['No',70,82,81,74,],['Undecided ',76,90,90,84,]]);

        var options = {
          title: 'Line graph for question "Not including this event, please estimate how much will you spend in the community during your visit, including accommodations, transportation, food, and gas, etc.)" against question "Would you describe this event as providing "good value?"'
          , colors:['#5D0F99','#2F543B','#BD2115','#D67314','#F92985','#0D85C7','#000D9C','#D9A5F6', '#27E80C', '#725F53']
        };

        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
<style>
div#wrapper {
max-width: 700px;
overflow:hidden;
background:#eee;
margin: 0 auto;
padding: 8px 8px 8px 8px;
border:1px solid black;
}

a{
    color:#000;

}

input.goback {
background-color: #ccc;
border: 1px outset #000;
color: #000;
padding: 4px;
margin-left: 2px;
}

</style>
</head>
<body>
<div id="wrapper">
<h1>Test Survey One</h1>

<form method="post" action="main.php">
<p>Show me average(s) on 
  <select name="oID">
    <option value="33">None</option>
  <option value="34">$1 - $50</option>
  <option value="35">$51 - $200</option>
  <option value="36">Over $200</option>
</select>

with these survey type(s): 
<select name="types">
<option value="0">All</option>
<option value="13">One week</option>
<option value="16">Paid</option>
<option value="18">Fair</option>
<option value="50">Live performance(s)</option>
<option value="51">Exhibition</option>
<option value="59">Community Pride</option>
<option value="54">Local foods / goods (grown or produced)</option>
<option value="53">Agriculture</option>
<option value="52">Art and Culture</option>
<option value="61">Industry</option>
<option value="62">Shop local</option>
<option value="39">Simcoe</option>
<option value="48">Fall</option>
<option value="65">Sale(s)</option>
<option value="66">Vendors</option>
<option value="67">Midway / rides</option>
<option value="68">Live music</option>
<option value="70">Live performance (not music or theatre)</option>
</select>

over a 12 month period.

<input type="hidden" name="sID" value="1342625918">
<input type="hidden" name="question1" value="5">
<input type="hidden" name="edit" value="average">
<input type="hidden" name="question2" value="17">
<input type="submit" name="submit" value="Go" class="goback">
</p>
</form>

<div id="chart_div" style="width: 675px; height: 500px;"></div>
<form method="post" action="main.php">
<p>
<input type="hidden" name="edit" value="survey">
<input type="hidden" name="sID" value="1342625918">
<input type="submit" value="Back To Statistics" class="goback">
</p>
</form>
</div>
</body>
</html>

Any thoughts on why this works sometimes quickly and others basically it appears to be timing out or something?

NOTE: it seams that the first time i pass a question1 and question2 number and load the page it times out. If i hit refresh it loads

  • 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-08T10:21:04+00:00Added an answer on June 8, 2026 at 10:21 am

    Probably related to the fact jsapi could be using http://www.google.com/chart? to generate them. It will timeout sometimes.

    To be 100% sure, it should use http://chart.googleapis.com/chart? Perhaps using google.Visualization construtor allows you to change the destination URL.

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

Sidebar

Related Questions

I have a table of survey answers, something like: date | q1 | q2
I have a table called Survey with a Group Column and a Subject Column
I am working on a survey created by PHP and MySQL. So the issue
I have a master table (hereafter called SURVEY) and a detail table (hereafter called
I have a table which contains a list of Surveys (PK is ID) CREATE
I have created an android application that calls (using kSOAP library) a SOAP based
I have created a website survey that is in the footer of our site.
Users can create surveys. Survey's have questions and questions have answer options (ie. a
I'm creating a wizard (really, a glorified survey) using jQuery Wizard Redux. I have
I have created a small survey web page on our company Intranet. This web

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.