**I am building a voting system, and am using phplot to plot the responses. Great tool so far!
The voting system allows admins to add new questions, and in the past I have been creating a plot file for each poll (plot-q1.php, plot-q2.php, etc). Each file opens a connection to the database, pulls the corresponding values, and then plots the info. The user adds the number of days the poll is valid (from today's date), and the results page should only plot questions that are not expired.
I would like to consolidate all of the plot-q#.php files into a single file that can accept 2 arguments, the 2 values that are being plotted. (ie; img src="plot.php?50,48" and set two local variables inside the plot.php files equal to the arguments)
Is this possible? Using a POST method doesn't seem like a viable option since the source code is generated inside a for loop (while there are still more valid, unexpired questions). I tried searching the discussion board but was unable to find an answer. Below is the source code from ang average plot-q#.php file:
connect_error) { die("Connection failed: " . $conn->connect_error); }
$sql="SELECT * FROM q1";
$result=mysqli_query($conn, $sql);
if($result != false) {
while($row=mysqli_fetch_assoc($result))
{
if($row['q1']==='For') $q1y += 1;
if($q1y>$max) $max = $q1y;
if($row['q1']==='Against') $q1n += 1;
if($q1n>$max) $max = $q1n;
}
}
$conn->close();
> **//Can i pull the ?50,48 and plug it in directly right here ??**
$data = array(
array('', $q1y, $q1n),
);
//
$plot = new PHPlot(200, 400);
$plot->SetImageBorderType('plain');
$plot->SetPlotType('bars');
$plot->SetDataType('text-data');
$plot->SetDataValues($data);
$plot->SetTitle('');
$plot->SetLegend(array('FOR', 'AGAINST'));
$plot->SetXTickLabelPos('none');
$plot->SetXTickPos('none');
$plot->SetPlotAreaWorld(NULL, 0, NULL, $max+1);
$plot->DrawGraph();
?>
**
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm glad you figured it out, but I just want to make sure you know to very carefully check before using anything from $_GET or $_POST to make sure it has nothing bad. You might find the PHP "Data Filtering" functions helpful, for example: filter_input().
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
**I am building a voting system, and am using phplot to plot the responses. Great tool so far!
The voting system allows admins to add new questions, and in the past I have been creating a plot file for each poll (plot-q1.php, plot-q2.php, etc). Each file opens a connection to the database, pulls the corresponding values, and then plots the info. The user adds the number of days the poll is valid (from today's date), and the results page should only plot questions that are not expired.
I would like to consolidate all of the plot-q#.php files into a single file that can accept 2 arguments, the 2 values that are being plotted. (ie; img src="plot.php?50,48" and set two local variables inside the plot.php files equal to the arguments)
Is this possible? Using a POST method doesn't seem like a viable option since the source code is generated inside a for loop (while there are still more valid, unexpired questions). I tried searching the discussion board but was unable to find an answer. Below is the source code from ang average plot-q#.php file:
connect_error) { die("Connection failed: " . $conn->connect_error); } $sql="SELECT * FROM q1"; $result=mysqli_query($conn, $sql); if($result != false) { while($row=mysqli_fetch_assoc($result)) { if($row['q1']==='For') $q1y += 1; if($q1y>$max) $max = $q1y; if($row['q1']==='Against') $q1n += 1; if($q1n>$max) $max = $q1n; } } $conn->close(); > **//Can i pull the ?50,48 and plug it in directly right here ??** $data = array( array('', $q1y, $q1n), ); // $plot = new PHPlot(200, 400); $plot->SetImageBorderType('plain'); $plot->SetPlotType('bars'); $plot->SetDataType('text-data'); $plot->SetDataValues($data); $plot->SetTitle(''); $plot->SetLegend(array('FOR', 'AGAINST')); $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->SetPlotAreaWorld(NULL, 0, NULL, $max+1); $plot->DrawGraph(); ?>**
(BTW: I have tried using $_GET with two variables in the URL, and it doesn't work, but with a single variable, it does work:
$max = 0;
$for = $_GET['for'];
$against = $_GET['against'];
if ($for > $against) $max = $for+1;
else if ($for < $against) $max = $against+1;
$data = array(
array('', $for, $against),
);
NEVERMIND! I was using the wrong syntax, it works fine with plot.php?for=100&against=200
I'm glad you figured it out, but I just want to make sure you know to very carefully check before using anything from $_GET or $_POST to make sure it has nothing bad. You might find the PHP "Data Filtering" functions helpful, for example: filter_input().