duanpai1920 2018-08-10 10:09
浏览 74

弹出显示数据库中的条目列表,以便在按下编辑按钮时进行选择

i am trying to design maintenance requisition form that is able to add, view, edit, delete data to and from a database table. im at a point of configuring the edit & view buttons. I want it to be able to fetch all requisitions saved in the database and show list in a pop up. I also want to be able to click on either data in the list and have all details show in the requisition form. From there, i want to be able to edit details and save again.

problem: i have searched the forums and have failed to get a starting point on how to do this. You guys helped with the session part and believed i could come back for help.

here is my code:

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>

Thank you.

  • 写回答

1条回答 默认 最新

  • doufei2328 2018-08-10 12:57
    关注

    You may want to go with the free dataTables framework (jQuery). This will give you the opportunity to select rows in your result table and display more details of the selected entries (which you may have not displayed in the main table).

    You can make the framework react to your defined button functions.

    It also implements search, pagination, etc..

    I have used this framework in two projects for similar purposes. I haven't used it in a popup window, but this should be possible.

    Link: https://datatables.net/

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料