对不起,英语不好。
此文本将填写此帖子的要求“看起来您的帖子主要是代码;请添加更多详细信息。”
这是我的代码
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var employee_id = $(this).attr("id");
$.ajax({
url:"select.php",
method:"post",
data:{employee_id:employee_id},
success:function(data){
$('#employee_detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
这是用于布局的<?php if(isset($_POST["employee_id"])) { $connect = mysqli_connect("localhost", "root", "", "db_hkrenewal"); $query = "SELECT * FROM tbl_form WHERE student_number = '".$_POST["employee_id"]."'"; $result = mysqli_query($connect, $query); $search = mysqli_real_escape_string($connect, $_POST["query"]); } while($row = mysqli_fetch_array($result)) { ?> <div class="table-responsive"> <table class="table table-bordered"> <tr> <td width="30%"><label>Student Number</label></td> <td width="70%"><?php echo $row['student_number'];?></td> </tr> <tr> <td width="30%"><label>Assigned Department</label></td> <td width="70%"><?php echo $row['assigned_dept'];?></td> <tr> <td width="30%"><label>Student Name</label></td> <td width="70%"><?php echo $row['student_name'];?></td> </tr> <tr> <td width="30%"><label>Course</label></td> <td width="70%"><?php echo $row['course'];?></td> </tr> <tr> <td width="30%"><label>Year Level</label></td> <td width="70%"><?php echo $row['year_level'];?></td> </tr> <tr> <td width="30%"><label>Contact Number</label></td> <td width="70%"><?php echo $row['contact_no'];?></td> </tr> <tr> <td width="30%"><label>Email Address</label></td> <td width="70%"><?php echo $row['email_add'];?></td> </tr> <tr> <td width="30%"><label>Vacant Time</label></td> <td width="70%"><?php echo $row['vacant_time'];?></td> <tr> <td width="30%"><label>HK Special</label></td> <td width="70%"><?php echo $row['hk_special'];?></td> </tr> <tr> <td width="30%"><label>Remarks</label></td> <td width="70%"><?php echo $row['Remarks'];?></td> </tr> <tr> <td width="30%"><label>HK Facilitator</label></td> <td width="70%"><?php echo $row['hk_faci'];?></td> </tr> <tr> <td width="30%"><label>Department Office</label></td> <td width="70%"><?php echo $row['dept_office'];?></td> </tr> <tr> <td width="30%"><label>Registration</label></td> <td width="70%"><img src ="<?php echo "storephotohere/". $row['registration'];?>" height="50%" width="100%"> </tr> <tr> <td width="30%"><label>Endorsement</label></td> <td width="70%"><img src ="<?php echo "storephotohere/". $row['endorse'];?>" height="50%" width="100%"> </tr> <tr> <td width="30%"><label>COM</label></td> <td width="70%"><img src ="<?php echo "storephotohere/". $row['com'];?>" height="50%" width="100%"> </tr> <tr> <td width="30%"><label>DTR</label></td> <td width="70%"><img src ="<?php echo "storephotohere/". $row['dtr'];?>" height="50%" width="100%"> </tr> </table></div> <?php }?>
table_names
id | name
这是index.html文件
//for user input
<input type="text" id="input_name">
//For search result
<div id="result"></div>
custom.js
//for each key up
$('body').on('keyup','#input_name', function(){
//get user input val
var val = $('#input_name').val();
//ajax call
$.ajax({
url: '/SearchController.php' // In here I just call for the controller . But you should
//insert relevant url here
method:'post',
//Passing user input val extracted as data
data:{ 'user_input' :val }
success:function(data){
$('#result').html(data);
},
error:function(errors){
console.log (errors);
}
});
});
SearchController.php
if(isset($_POST["user_input"])) {
//defining empty string to store values
$result = '';
$search_ name = $_POST['user_input'];
$connect = mysqli_connect("localhost", "root", "", "example_db");
//Query - **% sign at the end is must**
$query = "SELECT * FROM table_name WHERE name LIKE '$search_name%'";
$result = mysqli_query($connect, $query);
$search = mysqli_real_escape_string($connect, $search_ name );
while($row = mysqli_fetch_array($result))
{
//in here I'm looping a simple html label with fetched data from db and
// concatenating that data with the $result string
$result .= '<label> '.$row['name'].' <label>';
}
//Returning result this will be displayed in front-end
return $result;
}
始终使用用于测试
更多信息资源