всплывающее окно со списком записей в базе данных для выбора по нажатию кнопки редактирования

Я пытаюсь разработать форму заявки на обслуживание, которая может добавлять, просматривать, редактировать, удалять данные в и из таблицы базы данных. я в точке настройки редактирования & просмотр кнопок. Я хочу, чтобы он мог получать все заявки, сохраненные в базе данных, и отображать список во всплывающем окне. Я также хочу иметь возможность щелкнуть любую из данных в списке, и все детали отображаются в форме заявки. Оттуда я хочу иметь возможность редактировать детали и сохранить снова.

проблема: я искал форумы и не смог получить отправную точку о том, как это сделать. Вы, ребята, помогли с сессионной частью и поверили, что я могу вернуться за помощью.

вот мой код:

requisitionform.php

<?php
include("session.php");//include session to know logged in user

//check if submit button has been pressed
if(isset($_POST['submit'])){

//make a connection to server and database
include("DBconnect.php");

//define variables

$area_of_use=$_POST["area_of_use"];
$machine_name=$_POST["machine_name"];
$machine_code=$_POST["machine_code"];
$area=$_POST["area"];
$type=$_POST["type"];
$priority=$_POST["priority"];
$description=$_POST["description"];
$deadline=$_POST["deadline"];

//Save data into database

$sql="INSERT INTO requisition_table (
reqNo,RequestingDepartment,MachineName,
MachineCode,ForwardArea,MaintType,MaintPriority,
ProblemDescription,Deadline,RequestedBy,ReqDate)
VALUES (default,'$area_of_use','$machine_name',
'$machine_code','$area','$type','$priority',
'$description','$deadline','$login_session',now())";

$result=mysqli_query($con, $sql);

}

?>

<!DOCTYPE html>

<head>
<title>ZEKOmaint</title>

<style>
button {
width:1.8cm;
align:center;

}
.2{
align:center;
}

</style>
<?php
require "disablerequestform.php";
require "onchange.php";
require "req.php";
?>

<script src='https://code.jquery.com/jquery-2.1.3.min.js'></script>
</head>

<body>

<?php
if(isset($_POST['submit'])){
if ($result) {
echo "<script type='text/javascript'>alert('submitted successfully!')  </script>";
}
else
{
echo "<script type='text/javascript'>alert('failed!')</script>";
}
}
?>

<fieldset style="width:19cm;">
<legend><b>Maintenance Requistion</b></legend>

<fieldset id="2">
<button onclick="grayer('request',false);">ADD</button>
<button>VIEW</button>
<button>EDIT</button>
<button>DEL</button>
<input type="submit" name="submit" form="requestform" value="SAVE">
<button onclick="document.location.href='requisitionform.php'">CANC</button>
<button onclick="document.location.href='logout.php'">EXIT</button>
<button>PRINT</button>


</fieldset>
<br />
<form id= "requestform" action="requisitionform.php" method="POST">
<div id="request">
<table id="table1">
<tr><td>Requisition No.</td><td> <input type="int" name="req" size="10" id="req"></td>
<td>Requisition Date:</td><td><input type="date" name="date" size="10" value="<?php echo date('d-m-Y');?>"></td></tr>

<tr><td>Requesting Department: </td><td>

<select class="form-control" name="area_of_use" id='area_of_use' required>
<option value="" selected></option>

<option value="Wire Galvanizing">Wire Galvanising</option>
<option value="Wire Drawing">Wire Drawing</option>
<option value="Barbed Wire">Barbed Wire</option>
<option value="Utilities">Utlities</option>

</select>
</td>
<td>Forward to Area: </td><td><select name="area" required>
<option value="" selected></option>
<option value="Maintenance">Maintenance</option>

</select></td></tr>
<tr><td>Machine Name:</td>
<td><select name="machine_name" id="machine_name" class="form-control" required>



</select>
<script src='fetch.js'></script>

</td>
<td>Maintenance type:</td><td><select name="type" required>
<option value="" selected></option>
<option value="Preventive"> Preventive</option>
<option value="Corrective">Corrective</option>
<option value="Breakdown">Breakdown</option>
</select></td></tr>
<tr><td>Machine Code:</td><td><select name="machine_code" id = "machine_code" required></select> </td>
<script src='fetch2.js'></script>

<td>Maintenance Priority:</td><td><select name="priority" required>
<option value="" selected></option>
<option value="High" > High</option>
<option value="Moderate">Moderate</option>
<option value="Low">Low</option>
</select></td></tr>
</table>
<table id="table2">
<tr><td>Problem Description:</td> <td><textarea rows="2" cols="73"name="description" required="required"> </textarea></td></tr><br>
<tr><td>Deadline Time: </td> <td><input type="text" name="deadline" required></td></tr><br>
<tr><td>Cancel Remarks:</td> <td> <textarea rows="1" cols="73" name="cancel"></textarea></td></tr><br>
</table>

Requested by:<input type="text" name="asked" value="<?php echo $login_session;?>"<br>
Approved by:<input type="button" name="authorise" value="Authorise"><input type="text" name="approve">

</div>
</form>
</fieldset>

</body>
</fieldset>

</html>

disablerequestform.php

<script type="text/javascript">
function grayer(formId, yesNo) {
var f = document.getElementById(formId), s, opacity;
s = f.style;
opacity = yesNo? '40' : '100';
s.opacity = s.MozOpacity = s.KhtmlOpacity = opacity/100;
s.filter = 'alpha(opacity='+opacity+')';
for(var i=0; i<f.length; i++) f[i].disabled = yesNo;
}
window.onload=function(){grayer('request',true);}; // disabled by default
</script>

req.php

<?php
require 'DBconnect.php';

$sql = 'SELECT * FROM machines_table';

// Prepare the statement.
$statement = mysqli_prepare($con, $sql);

// Execute the statement.
mysqli_stmt_execute($statement);

// Get the result set from the prepared statement.
$result = mysqli_stmt_get_result($statement);

// Fetch the data and save it into an array for later use.
$details = mysqli_fetch_all($result, MYSQLI_ASSOC);

// Free the memory associated with the result.
mysqli_free_result($result);

// Close the prepared statement. It also deallocates the statement handle.
mysqli_stmt_close($statement);
?>

onchange.php

<script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function () {
$('#machinecode').change(function (event) {
var machine = $(this).val();

if (machine === 'Select') {
$('#machinename').val('');

} else {
$.ajax({
method: 'get',
dataType: 'json',
url: 'getinforeq.php',
data: {
'machine': machine
},
success: function (response, textStatus, jqXHR) {
if (!response) {
alert('No client data found.');
} else {
$('#machinename').val(response.machinename);

}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('An error occurred. Please try again.');
},
cmplete: function (jqXHR, textStatus) {
//...
}
});
}
});
});
</script>

Спасибо.

0

Решение

Вы можете захотеть использовать бесплатную платформу dataTables (jQuery). Это даст вам возможность выбрать строки в таблице результатов и отобразить дополнительные сведения о выбранных записях (которые вы, возможно, не отображали в основной таблице).

Вы можете заставить фреймворк реагировать на определенные вами функции кнопок.

Он также реализует поиск, нумерацию страниц и т. Д.

Я использовал эту структуру в двух проектах для аналогичных целей. Я не использовал его во всплывающем окне, но это должно быть возможно.

Ссылка на сайт:
https://datatables.net/

0

Другие решения

Других решений пока нет …