PHP help

Status
Not open for further replies.

cerbere

New Member
Messages
51
Reaction score
1
Points
0
Hi everyone,

Please look at these two pages first :

http://ixedix.x10hosting.com/MathRec/ (fourth problem)
http://ixedix.x10hosting.com/MathRec/plotit.htm

What I want to do on the second page is to plot the
function (time versus landing point) with default values,
and allow the visitor to try different W, L, VW, VL.
After clicking "Plot it", he should get the same page
with the new plot. That's the part that doesn't work
right now :pigeon:(

Do I need session functions to do that, or is there
a simpler way ?

Here is mrfishplot.php :

Code:
<?php
//Include the plotting code
require_once '/home/rocambol/librairies/phplot.php';

  $W = 0 + $_REQUEST['W'];
  $VW = 0 + $_REQUEST['VW'];
  $L = 0 + $_REQUEST['L'];
  $VL = 0 + $_REQUEST['VL'];

$data = array();
for($x = 0; $x <= $L; $x+=20)
  {
    $t = sqrt(pow($W, 2) + pow($x, 2)) / $VW + ($L - $x) / $VL; 
    $data[] = array('', $x, $t);
  }

//Define the plot object
$plot = new PHPlot(700, 425);

$plot->SetBackgroundColor(array(64,64,128));
$plot->SetDataColors('yellow');
$plot->SetTitleColor('white');
$plot->SetTextColor('white');
$plot->SetTickColor('white');
$plot->SetPlotType('lines');
$plot->SetDataType('data-data');
$plot->SetDataValues($data);

//$plot->SetPlotAreaWorld(0, 1000, $L, 1200);

$plot->SetXDataLabelPos('none');

$plot->SetXTickIncrement(400);
$plot->SetXLabelType('data');
$plot->SetPrecisionX(0);
$plot->SetDrawXGrid(True);

$plot->SetYTickIncrement(100);
$plot->SetYLabelType('data');
$plot->SetPrecisionY(0);
$plot->SetDrawYGrid(True);

$plot->SetGridColor('white');  // Misnamed, sets the axis color..

$plot->SetUseTTF(TRUE);
$plot->SetFont('generic', 'COURBD.TTF', 14);
$plot->SetFont('title', 'TIMESBD.TTF', 24);
$plot->SetFont('x_label', 'COURBD.TTF', 10);
$plot->SetFont('y_label', 'COURBD.TTF', 10);
$plot->SetFont('x_title', 'COURBD.TTF', 14);
$plot->SetFont('y_title', 'COURBD.TTF', 14);

$plot->SetTitle("The hungry fisherman");
$plot->SetXTitle("Landing point x (meters)");
$plot->SetYTitle("time (seconds)");

//Draw it
$plot->SetPrintImage(FALSE);  //We will add to it in a moment...
$plot->SetFileFormat('jpg');
$plot->DrawGraph();

$img = $plot->img;

$palegreen=imagecolorallocate($img,120,255,120);

$fontfile = '/home/rocambol/public_html/images/VERDANA.TTF';
imagettftext($img,18,0,300,100,$palegreen,$fontfile,
             "W = $W m   VW = $VW m/s");
imagettftext($img,18,0,300,140,$palegreen,$fontfile,
             "L  = $L m    VL  = $VL m/s");

//Now send it
$plot->PrintImage();

?>

Thanks for any help you can provide.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
I would use the XML-http request feature. It would update that image without changing the page. But you would have to learn AJAX
 

quantum1

New Member
Messages
68
Reaction score
0
Points
0
Would the code below work? I believe if you just include the "mrfishplot.php" right in the middle where your img is now, that it will work just as you have it, since "mrfishplot.php" is going to get the values your form is submitting. Also, I have modified your form to have "action=plotit.php". Create a new file "plotit.php" with the code below and see if it works.

<HTML>
<HEAD>
<meta http-equiv="content-type" content="text/html">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<TITLE>Fishplot</TITLE></HEAD>
<BODY bgcolor=#000000><font color=#ffffff>
<img src="http://ixedix.x10hosting.com/images/zero2six.jpg">
<P><H1>Example plot</H1>
<P><b><font face="Courier New,Courier"><br>

<!--<img src="http://ixedix.x10hosting.com/MathRec/mrfishplot.php?W=1000&L=2000&VW=2&VL=3"><br>-->

<?php require '/home/rocambol/librairies/mrfishplot.php'; ?>

<!--<form action="mrfishplot.php" method="post">-->

<form action="plotit.php" method="post">
<!--<form action="chkfsh.php" method="post">-->

<!--<form action="vardmp.php" method="post">-->
W : <input name="W" type="text" size=4 maxlength=8 value=1000 /> meters&nbsp;
VW : <input name="VW" type="text" size=4 maxlength=8 value=2 /> meters/sec<br>
L : <input name="L" type="text" size=4 maxlength=8 value=2000 /> meters&nbsp;
VL : <input name="VL" type="text" size=4 maxlength=8 value=3 /> meters/sec
<input value="Plot it" type="submit" />

</form>

</body></html>
 

cerbere

New Member
Messages
51
Reaction score
1
Points
0
Thanks for the suggestion, Quantum1, but that
doesn't work. The image is transmitted as text...

To correctly transmit an image with PHPlot,
one must use an HTML tag like
<img src=".../produce_image.php">
otherwise the content-type is incorrect.
So require() or include() can't do the job :pigeon:(

But I'll keep at it and inform you if I make it work
without JavaScript or session use.
 

quantum1

New Member
Messages
68
Reaction score
0
Points
0
Can you use the php header command to set the content-type so that the content type returned by '/home/rocambol/librairies/mrfishplot.php' is type image?

Just trying to see if the simple require can work somehow. :)
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
Can you use the php header command to set the content-type so that the content type returned by '/home/rocambol/librairies/mrfishplot.php' is type image?

Just trying to see if the simple require can work somehow. :)

It won't, gotta burst your bubble there.

Soon as the very first < went out (the < in <html>), Headers were sent identifying the page as html; header() will return an error/warning along these lines:

Cannot send headers; Headers already sent on line 59850683969;




The good news is I think there's a relatively easy way to fix it without actually messing up the plotting code (or much of the page at all really).

Code:
<img src="http://ixedix.x10hosting.com/MathRec/mrfishplot.php?W=1000&L=2000&VW=2&VL=3"><br>
^ That's the code displaying the basic image, as you've already got it in the file.

Let's adjust that a bit (WARNING: NEW PAGE NEEDS TO BE .PHP!!!!!)

Replace the previous line with this:

Code:
<?php

$w=$_REQUEST['W'];
$vw=$_REQUEST['VW'];
$l=$_REQUEST['L'];
$vl=$_REQUEST['VL'];
if (empty($w)) { $w=1000; }
if (empty($vw)) { $vw=2; }
if (empty($l)) { $l=2000;}
if (empty($vl)) { $vl=3; }
print "<img src='http://ixedix.x10hosting.com/MathRec/mrfishplot.php?W={$w}&L={$l}&VW={$vw}&VL={$vl}'><br>";
?>
What it does:

Sets $w, $vw, $l, and $vl to their GET or POST counterparts. If they happen to not be defined (such as on first page view), it sets them to their defaults (the 'empty' statements).

Then it just prints back a standard image tag like the one you had, substituting the values into their original places.



Far as the rest of it goes, it seems you've already got the form set up so when you hit submit, it's reloading the exact same page, but passing it all that extra data. So swapping in the new php code in place of that <img> tag -should- be enough to make it work.


Or at least it's working for me; I copied some of the code you had and stuck it in a testing file I use - it's passing the data and re-plotting correctly here :)
 

cerbere

New Member
Messages
51
Reaction score
1
Points
0
Thanks a lot, Livewire, your method works like a charm !

I also plug the parameters back into the form, using PHP
print statements inserted into the form. So my original
plotit.htm is now
http://ixedix.x10hosting.com/MathRec/plotit.php :

Code:
<HTML>
<HEAD>
<meta http-equiv="content-type" content="text/html">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<TITLE>Fishplot</TITLE></HEAD>
<BODY bgcolor=#000000><font color=#ffffff>
<img src="http://ixedix.x10hosting.com/images/zero2six.jpg">
<P><H1>Example plot</H1>
<P><b><font face="Courier New,Courier"><br>

<?php
$w=$_REQUEST['W'];
$vw=$_REQUEST['VW'];
$l=$_REQUEST['L'];
$vl=$_REQUEST['VL'];
if (empty($w)) { $w=1000; }
if (empty($vw)) { $vw=2; }
if (empty($l)) { $l=2000;}
if (empty($vl)) { $vl=3; }
print "<img src='http://ixedix.x10hosting.com/MathRec/mrfishplot.php?W={$w}&L={$l}&VW={$vw}&VL={$vl}'><br>";
?>

<br><br>
<form action="plotit.php" method="post">
W : <input name="W" type="text" size=4 maxlength=8 value=
  <?php print $w ?>
  /> meters&nbsp;
VW : <input name="VW" type="text" size=4 maxlength=8 value=
  <?php print $vw ?>
  /> meters/sec<br>
L : <input name="L" type="text" size=4 maxlength=8 value=
  <?php print $l ?>
  /> meters&nbsp;
VL : <input name="VL" type="text" size=4 maxlength=8 value=
  <?php print $vl ?>
  /> meters/sec
<input value="Plot it" type="submit" />
</form>

</body></html>

If I'm not too lazy, I'll add some validation of the input values...
 

tittat

Active Member
Messages
2,478
Reaction score
1
Points
38
Thread Closed by user Request.
*****Thread Closed******
 
Status
Not open for further replies.
Top