0

my program works like this. there are three buttons on html page which are linking to three different php files which result in xml, result are based on fixed sql command in oracle. when user click on one of the button eg.

    <p><input class="fetchSeries" type="button" value="CurrValue">  
  <a href="connectyf.php"> </a>  
  <span></span>
  </p>

it will then trigger the below ajax, and to plot a graph on html page

 $("input.fetchSeries").click(function () {
     var button = $(this);  
     var dataurl = button.siblings('a').attr('href');
     $.ajax({
     url: dataurl,
     type: "GET",
 cache: false,
     success: function (data2) {
      $(data2).find('node').each(function(){
      var currV = $(this).find('snv').text();
      var dateT =   ($(this).find('agev').text())*1000;
      var d2 = [];
      d2.push(dateT, currV);
      dataset.push(d2);
      button.siblings('span').text('Fetched '  + ', first point: ' );
     })
   data.push(dataset);
   $.plot(placeholder, data,options);
   dataset = [];
  }
    }); 
  });

sql command :

   $sql = "SELECT TO_CHAR(DATETIME, 'YYYY-MM-DD HH24:MI:SS') AS DATETIME, PRESENTSTATE
   FROM T00000000_01080413 WHERE DATETIME BETWEEN '04-OCT-11' AND '15-OCT-11' ";

what i need to do now is place four user input field and one button, click the button to control the sql command, something should be like this in php page if im not mistaken

$sql = "SELECT TO_CHAR(DATETIME, 'YYYY-MM-DD HH24:MI:SS') AS '$_POST[datetime]', '$_POST[vall]' FROM T00000000_01080413 WHERE DATETIME BETWEEN '$_POST[startdate]' AND '$_POST[enddate]' ";

now im a bit headache how do i use the user input as sql command and plot the graph once i click the button?

is it may use the input[name=startdate]; something like that? soooo headache now.please inspire me.... thx so much in advance

  <form method="post" > 
    <div> 
        <input type="text" class="form-text required" value="" size="15" id="edit-name" name="startd" maxlength="60"> 
        <input type="text" class="form-text required" value="" size="15" id="edit-name" name="endd" maxlength="60"> 
        <input type="text" class="form-text required" value="" size="15" id="edit-name" name="pname" maxlength="60"> 
        <input type="text" class="form-text required" value="" size="15" id="edit-name" name="val" maxlength="60"> 
      <input class="fetchSeries" type="button" value="draw graph!"/> 
    </div>
  </form> 














$.ajax({
  type: "POST",
  url: "connectyf1.php",
  data: "startdate="+startdt+"&enddate="+enddt+"&tablename="+tname+"&parameter"+param,
  success: function(grapHtml){

    $("#graph").append(graphHtml); 

 $.ajax({
               url: "connectyf1.php",
               type: "GET",
       cache: false,
               success: function (data2) { 
  $(data2).find('node').each(function(){
  var currV = $(this).find('snv').text();
  var dateT =   ($(this).find('agev').text())*1000;
  var d2 = [];
  d2.push(dateT, currV);
   dataset.push(d2);
  button.siblings('span').text('Fetched '  + ', first point: ' );
  })
   data.push(dataset);
    $.plot(placeholder, data,options);
        dataset = [];
  }
    });

   }
  });
13
  • I'm not sure if i understand your question. are you looking for the jquery selector to select an input element by its name-attribute ? That 's done with $('input[name="startd"]') Commented Oct 17, 2011 at 13:29
  • I dont really understand what is the problem? you want to send values to the php and return a graph? Commented Oct 17, 2011 at 13:30
  • $('input[name="startd"]') yup thats part of the answer i've looking for...the tough part is how and where do i use $('input[name="startd"]') to send user input to php as part of the sql command? Commented Oct 17, 2011 at 13:47
  • i believe in php file i can just simply use @post to get the date sent from html...but how can i send...? Commented Oct 17, 2011 at 13:49
  • Still not sure if i follow, but in your example, you use $.ajax with type="GET". This means that you send your values as get parameters in the url, like www.example.com/connectyf.php?startd=2011-10-17. In php, you are able to access get parameters in the $_GET[] array. $_POST[] array is for a submission with method 'post', not 'get' Commented Oct 17, 2011 at 14:10

1 Answer 1

0

If you are using jquery (version 1.5 or higher) you can make an ajax call by using this:

var startd = $('input[name="startd"]').val();

$.ajax({
  type: "POST",
  url: "some.php",
  data: "startd="+startd+"&location=Boston",
  success: function(grapHtml){
    $("#graph").append(graphHtml);
  }
});

This makes a post request to some.php. This file will receive $_POST['startd'] and $_POST['location'] values.

Sign up to request clarification or add additional context in comments.

1 Comment

again my greatest thank for your help and time. but not quite sure about the $("#graph").append(graphHtml);? ive seen ppl do $('body div').text(data); . is it a function to print out result?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.