Search code examples
phpjavascriptjspflot

how to execute my php code in jsp


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


Solution

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