Closed Thread
Results 1 to 8 of 8

Thread: PHP help

  1. #1
    cerbere is offline x10Hosting Member cerbere is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    51

    PHP help

    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 :>(

    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.

  2. #2
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: PHP help

    I would use the XML-http request feature. It would update that image without changing the page. But you would have to learn AJAX
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  3. #3
    quantum1's Avatar
    quantum1 is offline x10Hosting Member quantum1 is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    near Nashville, TN
    Posts
    68

    Re: PHP help

    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>
    Two rules of development:
    1) Computers work for people; People do not work for computers
    2) Maintainability is all that matters.

  4. #4
    cerbere is offline x10Hosting Member cerbere is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    51

    Re: PHP help

    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 :>(

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

  5. #5
    quantum1's Avatar
    quantum1 is offline x10Hosting Member quantum1 is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    near Nashville, TN
    Posts
    68

    Re: PHP help

    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.
    Two rules of development:
    1) Computers work for people; People do not work for computers
    2) Maintainability is all that matters.

  6. #6
    Livewire's Avatar
    Livewire is offline Abuse Compliance Officer Livewire is a glorious beacon of lightLivewire is a glorious beacon of light
    Join Date
    Jun 2005
    Location
    Behind a keyboard.
    Posts
    8,998

    Re: PHP help

    Quote Originally Posted by quantum1 View Post
    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


    TOS breakers will be suspended regardless of race, creed, national origin, hair color, or favorite food. Thanks for your understanding!

  7. #7
    cerbere is offline x10Hosting Member cerbere is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    51

    Re: PHP help

    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...

  8. #8
    tittat's Avatar
    tittat is offline x10 Spammer tittat is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Kerala,India
    Posts
    2,479

    Re: PHP help

    Thread Closed by user Request.
    *****Thread Closed******
    PLAY ONLINE GAMES
    WWW.TMONDO.COM PlayFar Flash Games
    Former X10 Forum Senior Moderator(Retired)


Closed Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. currently have an application pending php
    By biomasti in forum Free Hosting
    Replies: 1
    Last Post: 09-03-2008, 01:58 PM
  4. php errors galore
    By DMG Online in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 05-17-2008, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers