Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 642613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:11:33+00:00 2026-05-13T21:11:33+00:00

<?php include_once(‘db.php’); $location = $_POST[‘location’]; $doctor = $_POST[‘doctor’]; $patient_id = $_POST[‘patient_id’]; if(($location != )

  • 0
<?php
include_once('db.php');
$location = $_POST['location'];
$doctor = $_POST['doctor'];
$patient_id = $_POST['patient_id'];

if(($location != "") && ($doctor != "")) {
  $sql = "select Name,Age,Gest_age,Weight from rop_form where Location = '".$location."' and Doctor = '".$doctor."' and Patient_id = '".$patient_id."'";
  $result = mysql_query($sql);
  $myresult  = "";
  while($row = mysql_fetch_array($result)) {
    $myresult1['Patient_id'] = 'R'.$patient_id; 
    $myresult1['Name'] = $row['Name']; 
    $myresult1['Age'] = $row['Age']; 
    $myresult1['Weight'] = $row['Weight']; 
    $myresult1['Gest_age'] = $row['Gest_age']; 
  }
  $myresult = json_encode($myresult1); 
}
else {
  $myresult .= "";
}
echo $myresult;
?>

This is my PHP code.

This is the jQuery code.

$("#patient_id").change(function() {
  $.post("/diabetes/patient_detail_change.php",{ location:$("#location").val(),doctor:$("#doctor").val(),patient_id:$("#patient_id").val()} ,function(json_data) {
    alert(json_data);
    //var my_json = //{"Patient_id":"R00020","Name":"admin","Age":"12","Weight":"67","Gest_age":"2"//};
    $.each(json_data, function(key,value) {
      alert(key + ': ' + value);
      if(key == 'Name'){ $("#name").val(value); }
      if(key == 'Age'){ $("#age").val(value); }
      if(key == 'Weight'){ $("#ropweight").val(value); }
      if(key == 'Gest_age'){ $("#gest_age").val(value); }
    });
  });
});

alert(json_data); this line prints properly like

{"Patient_id":"R00006","Name":"admin","Age":"12","Weight":"67","Gest_age":"2"} which is the fomat required for jquery

But the .each loop statement which is present like: alert(key + ': ' + value); does not print like Patient_id : R00006 and all .but it prints like 0:{ 1:P 2:a 3:t 4:i ..what might be the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:11:33+00:00Added an answer on May 13, 2026 at 9:11 pm

    In addition to Matt Ellen’s answer, the $.each() method is for looping over JavaScript arrays and array-like objects (that have a length property). PHP’s associative arrays (keyword->value) are converted into a native JavaScript object instead. You could use a for...in loop instead:

    for (var key in json_data) { 
       alert(key + ': ' + json_data[key]); 
       if(key == 'Name'){ $("#name").val(json_data[key]);} 
       if(key == 'Age'){ $("#age").val(json_data[key]);} 
       if(key == 'Weight'){ $("#ropweight").val(json_data[key]);} 
       if(key == 'Gest_age'){ $("#gest_age").val(json_data[key]);} 
    }
    

    But you probably don’t need the loop. You can just use:

    $.post (
      "/diabetes/patient_detail_change.php",
      { 
        location:$("#location").val(),
        doctor:$("#doctor").val(),
        patient_id:$("#patient_id").val()
      }, 
      function (json_data){
        if ("Name" in json_data) { $("#name").val(json_data.Name);}
        if ("Age" in json_data) { $("#age").val(json_data.Age);}
        if ("Weight" in json_data) { $("#ropweight").val(json_data.Weight);}
        if ("Gest_age" in json_data) { $("#gest_age").val(json_data.Gest_age);}
      }, 
      "json"
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
<?php include_once('booter/login/includes/db.php'); $query=SELECT * FROM shells; $result=mysql_query($query); while($row=mysql_fetch_array($result, MYSQL_ASSOC)){ $hash = @md5_file($row['url']); echo $hash
I made a while loop in php: <?php include_once(connect.php); $search=mysql_query(SELECT * from chat ORDER
<?php include_oncescripts/connect.php; $sql = mysql_query(SELECT * FROM Tabletest ORDER BY Points DESC, PP DESC,
I'm unable to perform the desired event. <?php include_once 'includes/db.php'; $result = mysql_query('SELECT country,code
Is it more efficient to use PHP's include_once or require_once instead of using a
I have the following code: if (include_once(dirname(__FILE__).'/file.php') || include_once(dirname(__FILE__).'/local/file.php') ) { This causes an
When I try to include a file using include_once in php which shows warning
I have a page with a list of items initially loaded from a include_once('show_calendarV2.php');
Here the code: <?php include_once 'config.php'; // Connect to database $conn = oci_connect($dbuser, $dbpasswd,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.