我创建了一个简单的php搜索,搜索id如果有匹配它会显示firstname和lastname,我的问题是我想把数据传递给我的modal,我的modal里面有一个文本框firstname和lastname。有没有可能在我搜索了id之后,它会仅仅使用php和html在modal上显示数据?希望你能帮助我。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
以下是我的php代码:
<?php
include_once('connection.php');
$output = '';
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$sql = "SELECT id, fname, lname FROM test WHERE id LIKE '$searchq'" ;
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);
if($count == 0){
$output ='No results!';
}else{
while($row = mysqli_fetch_array($result))
{
$fname = $row['fname'];
$lname = $row['lname'];
$id = $row['id'];
$output .= '<div>'.$fname.''.$lname.'</div>';
}
}
}
?>
以下是我的示例php搜索表单和模式代码:
<form method="post">
<div class="md-form input-group">
<input type="search" class="form-control added-padding-2" placeholder="Search..." name="search" id="textsend"
maxlength="11" >
<span class="input-group-btn">
<button class="btn btn-pink btn-rounded my-0" type="submit" style="border-radius: 50px;" data-dismiss="modal"
type="submit" href="#exampleModal3" data-toggle="modal" data-target="#exampleModal3" target="_blank"
role="button" id="button">Search</button>
</span>
</div>
<?php print $output;?>
</div>
</form>
<div class="modal fade" id="exampleModal3" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" data-backdrop="false">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header blue accent-1">
<h3 class="mt-2" style="color:white;"><i class="fa fa-user-circle"></i> User Information:</h3>
<a href="index3.php" button type="btn" class="close" aria-label="Close">
<span aria-hidden="true">×</span></a>
</div>
<div class="modal-body">
<form action="index3.php" method="post" >
<div class="row">
<div class="col">
<div class="md-form mt-0">
<input type="text" class="form-control" name="firstname" placeholder="First name" id="firstname" value="<?php print $output;?>" required >
</div>
</div>
<div class="col">
<div class="md-form mt-0">
<input type="text" class="form-control" placeholder="Last name" name="lastname" id="lastname" value="<?php print $output;?>" required >
</div>
</div>
</div>
<div class="text-center mt-2">
<button type="submit" class="btn btn-info" style="width:98%; ">Log in <i class="fa fa-sign-in ml-1"></i></button>
</div>
</form>
</div>
</div>
</div>
</div>
提前谢谢。
暂无答案!
目前还没有任何答案,快来回答吧!