-1
<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -->
<html>
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Flot Examples</title>
    <link href="layout.css" rel="stylesheet" type="text/css">
    <!--[if lte IE 8]><![endif]-->
    <script  type="text/javascript" src="./js/excanvas.min.js"></script>
     <script type="text/javascript" src="./js/jquery.js"></script>
    <script  type="text/javascript" src="./js/jquery.flot.js"></script>
 </head>
    <body>
    <h1>Flot Examples</h1>

    <div id="placeholder" style="width:600px;height:300px;"></div>

    <p>Simple example. </p>
<?php

$server = "localhost";
    $user="harish";
    $password="password";  
    $database = "db";

    $connection = mysql_connect($server,$user,$password);
    $db = mysql_select_db($database,$connection);

query = "SELECT xval,yval FROM flottable";
    $result = mysql_query($query);        

    while($row = mysql_fetch_assoc($result))
    {
        $dataset1[] = array($row['xval'],$row['yval']);
    }

?>

<script type="text/javascript">
$(function () {
    var dataset1 = <?php echo json_encode($dataset1); ?>;

    $.plot($("#placeholder"), [ dataset1 ]);


}); 
/* $(function () {
     var d1 = [];
        for (var i = 0; i < 14; i += 0.5)
            d1.push([i, Math.sin(i)]); 
         $.plot($("#placeholder"), [ d1 ]);     });
 */
 </script>

 </body>
</html>

Guys this is my jsp code i am trying to retrieve data from my database and trying to plot it on FLOTCHART from 3dyas i had been googling i separately executed the php code in my eclipse juno it is working means $row['xval'] & $row['yval'] both gets the values from db correctly.but still i dont know why graph is plotted if i run this jsp file.I think i am doing something wrong i dont know where i also googled to get data from database in javascript but there also i got same result we should use php for this any help or guidance is appreciated

Reference: Retrieve data from mysql by php to create flot graph

Community
  • 1
  • 1
HkFreaKuser1673718
  • 759
  • 4
  • 13
  • 31
  • 1
    Why would you use PHP inside a JSP? That's like using C++ code inside a Java class and hope it works? Or talk in Chinese to a French guy and hope he understands. – JB Nizet Nov 03 '12 at 10:59
  • JB Nizet Ya i too add that doubt But check the Refernce see what John M has posted there he didnt mention which file its is so i assumed its jsp or Html file and tried in Both hehe.Since i dont know about javascript or php or JSON or FLOT i did that.So how to go about it? – HkFreaKuser1673718 Nov 03 '12 at 11:04

1 Answers1

1

I think you are confusing JavaScript and Java. JSP is short for Java Server Pages. Java and JavaScript are completely different languages.

The code you have shown above contains no Java, only PHP and JavaScript.

The .JSP file extension is for Java Server Pages and is not needed to run JavaScript. JavaScript can be run in PHP and HTMLfiles.

Mitch Satchwell
  • 4,770
  • 2
  • 24
  • 31
  • MitchS But we can embedded javascript in jsp right i know it coz i have used it as in above example using script tag.Ok lets not argu Do u have any solution to my above question i want to get the values from db to the javascript so that i can plot graph.I tried the above code with .html extension but no proper result.Which language should i use? – HkFreaKuser1673718 Nov 03 '12 at 11:13
  • Yes, you can. You can also do this in PHP files, which is why using a PHP file when using PHP and JavaScript makes a lot more sense than a JSP file. – Mitch Satchwell Nov 03 '12 at 11:16
  • but i want the above 3 script tags which is refering 3 .js file and div tag and the last Script tag.Can i include all of this in Php as well? and after this can i call this in my javaee web project which has jsp/java class/html? – HkFreaKuser1673718 Nov 03 '12 at 11:22