#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    7
    Rep Power
    0

    Error Encountered when using PHPlot to plot graph.


    Hi, i am new to php. Any help will be much appreciated.

    There is an error with the query although i do not know what to change to make it work.

    Any ideas?

    [php]
    <?php
    //Include the code
    require_once 'phplot.php';
    //Define the object
    $plot = new PHPlot(800,600);
    //Define some data

    $dbhost = "localhost";
    $username="root";
    $password="";
    $database="roy";


    mysql_connect($dbhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");

    $query="SELECT * FROM try2";

    $r = mysql_query($query);
    if (!$r) exit();
    $data = mysql_fetch_array();
    $n_rows = mysql_fetch_row($r);
    for ($i = 0; $i < $n_rows; $i++) $data[] = mysql_fetch_row($r, $i);


    $plot->SetDataValues($data);

    //Turn off X axis ticks and labels because they get in the way:
    $plot->SetXTickLabelPos('none');
    $plot->SetXTickPos('none');
    //Draw it
    $plot->DrawGraph();
    ?>
    [php]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,466
    Rep Power
    594
    1) Please enclose your code in [ PHP ] tags. See the sticky at the top of this forum.
    2) Don't use the depreciated MySQL extensions. You should be using PDO.
    3) Since we are not clairvoyant, you will need to post the error message.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by gw1500se
    2) Don't use the depreciated MySQL extensions. You should be using PDO.
    Please, it's "deprecated". When I told you last time, you said it was a typo. But who makes the same typo every time he writes a word?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,466
    Rep Power
    594
    I do, obviously. Deprecate is a word I rarely use compared to depreciate so that is a natural typo for me. I don't know why I'm explaining myself to you anyway. Why are you so concerned with my typos in the first place? Is there anyone on this forum that you think is too dumb to understand what I meant?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,990
    Rep Power
    375
    Originally Posted by Jacques1
    Please, it's "deprecated". When I told you last time, you said it was a typo. But who makes the same typo every time he writes a word?
    ...every time THEY write a word

    If you are going to pick on someone, at least make sure your own grammar/English is acceptable or was that a typo?


    PS> I am not having a go at you.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,466
    Rep Power
    594
    A special note to jeremsp. My apologies for being the vehicle through which someone decided to highjack your thread. Please resume your question.

    Comments on this post

    • Jacques1 agrees : C'mon, don't be so thin-skinned.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    7
    Rep Power
    0
    Hi I thought i have enclosed the code within the [PHP] tags.
    Sorry if i made any mistakes quite new here.

    The error of the query is


    Warning: mysql_fetch_array() expects at least 1 parameter, 0 given in C:\xampp\htdocs\PHPlot\phplot-5.8.0\test1.php on line 21

    Warning: mysql_fetch_row() [function.mysql-fetch-row]: The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH in C:\xampp\htdocs\PHPlot\phplot-5.8.0\test1.php on line 23


    and for the error on line 23 it just keep repeating until it cause lags and the window closes it. Did i loop it somewhere and cause it to repeat continuously? I really have no idea.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,466
    Rep Power
    594
    Untested but you replace all the obsolete MySQL stuff with this. You may need to reformat $data to get it the way you want.
    PHP Code:
    try {
       
    $conn=new PDO("mysql:$dbhost;dbname=$database",$username,$password);
    }
    catch(
    PDOException $e) {
       die(
    "Unable to connect to database: ".$e->getMessage();
    }
    $query="SELECT * FROM try2";

    $results=$conn->query($query);
    if (
    $results->rowCount()==0) exit();
    $data=$results->fetchAll(); 
    P.S. You forgot the '/' in your closing PHP tag.
    Last edited by gw1500se; December 11th, 2012 at 03:31 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    7
    Rep Power
    0
    Hi. I have found a solution to the query and it works and a graph could be displayed.
    PHP Code:
    $query="SELECT * FROM try1";
    $result=mysql_query($query);

    while(
    $row=mysql_fetch_assoc($result)){
        
    $data[]=$row;

    By using this query it works.
    Thank you all for your help.

    Comments on this post

    • gw1500se disagrees : Again, don't use the MySQL extensions

IMN logo majestic logo threadwatch logo seochat tools logo