У меня есть таблица предписаний в mysql, использующая php-pdo и jsgrid, и я хочу знать, как я могу получить Patient_id моей таблицы пациентов и вставить ее в таблицу предписаний. Я попытался добавить микс инициализировать Patient_id с помощью PHP MySQL, но он не работает, единственный способ, которым я могу получить Patient_id, это сделать кнопку. но требования в том, что на странице Patient_id уже есть и только получить и вставить в базу данных. извините за мой плохой английский
это мой код
$(function () {
"use strict";
$.ajax({
type: "GET",
url: "action/fetch_medicine.php"
}).done(function (medicine) {
medicine.unshift({
medicine_id: "0",
medicine_name: ""
});
$('#grid_table').jsGrid({
width: "100%",
height: "460px",
filtering: true,
inserting: true,
editing: true,
sorting: true,
paging: true,
autoload: true,
pageSize: 10,
pageButtonCount: 5,
deleteConfirm: "Do you really want to delete data?",
controller: {
loadData: function (filter) {
return $.ajax({
type: "GET",
url: "action/fetch_data.php",
data: filter
});
},
insertItem: function (item) {
return $.ajax({
type: "POST",
url: "action/fetch_data.php",
data: item
});
},
updateItem: function (item) {
return $.ajax({
type: "PUT",
url: "action/fetch_data.php",
data: item
});
},
deleteItem: function (item) {
return $.ajax({
type: "DELETE",
url: "action/fetch_data.php",
data: item
});
}
},
fields: [
{
name: "id",
type: "hidden",
css: 'hide'
},
{
//not working -----> name: "patient_id",
type: "hidden",
css: 'hide',
valueField: "patient_id",
textField: "patient_id"
},
{
name: "date_time",
type: "hidden",
css: 'hide',
valueField: "date_time",
textField: "date_time"
},
{
name: "medicine",
title: "Medicine",
type: "select",
width: 100,
items: medicine,
valueField: "medicine_name",
textField: "medicine_name"
},
{
name: "breakfast",
type: "text",
width: 50,
validate: "required"
},
{
name: "lunch",
type: "text",
width: 50,
validate: "required"
},
{
name: "dinner",
type: "text",
width: 50,
validate: function (value) {
if (value > 0) {
return true;
}
}
},
{
type: "control",
modeSwitchButton: true,
editButton: true
}
]
});
});
});
это мой php код
<?php
//fetch_data.php
$connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");
$method = $_SERVER['REQUEST_METHOD'];
if($method == 'GET')
{
$data = array(
':date_time' => "%" . $_GET['date_time'] . "%",
':medicine' => "%" . $_GET['medicine'] . "%",
':breakfast' => "%" . $_GET['breakfast'] . "%",
':lunch' => "%" . $_GET['lunch'] . "%",
':dinner' => "%" . $_GET['dinner'] . "%"
);
$query = "SELECT * FROM consultation WHERE date_time LIKE :date_time AND medicine LIKE :medicine AND breakfast LIKE :breakfast AND lunch LIKE :lunch AND dinner LIKE :dinner ORDER BY consultation_id DESC";
$statement = $connect->prepare($query);
$statement->execute($data);
$result = $statement->fetchAll();
foreach($result as $row)
{
$output[] = array(
'consultation_id' => $row['consultation_id'],
'patient_id' => $row['patient_id'],
'date_time' => $row['date_time'],
'medicine' => $row['medicine'],
'breakfast' => $row['breakfast'],
'lunch' => $row['lunch'],
'dinner' => $row['dinner']
);
}
header("Content-Type: application/json");
echo json_encode($output);
}
if($method == "POST")
{
date_default_timezone_set('Asia/Manila');
$date_time=date("F j, Y - g:i a");
$date=date("F j, Y");
$data = array(
':patient_id' => $_POST['patient_id'],
':date_time' => $date_time,
':medicine' => $_POST['medicine'],
':breakfast' => $_POST["breakfast"],
':lunch' => $_POST["lunch"],
':dinner' => $_POST["dinner"]
);
$query = "INSERT INTO consultation (patient_id, date_time, medicine, breakfast, lunch, dinner) VALUES (:patient_id, :date_time, :medicine, :breakfast, :lunch, :dinner)";
$statement = $connect->prepare($query);
$statement->execute($data);
}
if($method == 'PUT')
{
parse_str(file_get_contents("php://input"), $_PUT);
date_default_timezone_set('Asia/Manila');
$date_time=date("F j, Y - g:i a");
$date=date("F j, Y");
$data = array(
':consultation_id' => $_PUT['consultation_id'],
':date_time' => $date_time,
':medicine' => $_PUT['medicine'],
':breakfast' => $_PUT['breakfast'],
':lunch' => $_PUT['lunch'],
':dinner' => $_PUT['dinner']
);
$query = "UPDATE consultation
SET date_time = :date_time,
medicine = :medicine,
breakfast = :breakfast,
lunch = :lunch,
dinner = :dinner
WHERE consultation_id = :consultation_id
";
$statement = $connect->prepare($query);
$statement->execute($data);
}
if($method == "DELETE")
{
parse_str(file_get_contents("php://input"), $_DELETE);
$query = "DELETE FROM consultation WHERE consultation_id = '".$_DELETE["consultation_id"]."'";
$statement = $connect->prepare($query);
$statement->execute();
}
?>