recherche dynamique php mysql ajax avec possibilité de modifier
bonjour j'ai besoin de votre aide:
je voudrai créer une page web où on puisse rechercher dynamiquement les résultats dans une base de données.
j'ai fais la recherche mais je peux pas ouvrir la ligne choisi dans une page php Edit.php pour la modifier
voici mes codes
page index.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>recherche</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<br />
<br />
<br />
<h2 align="center">recherche</h2><br />
<div class="form-group" accept-charset="utf-8">
<div class="input-group">
<span class="input-group-addon">search</span>
<input type="text" name="search_text" id="search_text" placeholder="Search by Customer Details" class="form-control" />
</div>
</div>
<br />
<div id="result"></div>
</div>
<div style="clear:both;"></div>
<br />
<br />
<br />
<br />
</body>
</html>
<script>
$(document).ready(function(){
load_data();
function load_data(query)
{
$.ajax({
url:"fetch.php",
method:"post",
data:{query:query},
success:function(data)
{
$('#result').html(data);
}
});
}
$('#search_text').keyup(function(){
var search = $(this).val();
if(search != '')
{
load_data(search);
}
else
{
load_data();
}
});
});
</script> |
page fetch.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
<?php
$connect = mysqli_connect("Localhost", "root", "", "Db_mysql");
$connect->set_charset("utf8");
$output = '';
if(isset($_POST["query"]))
{
$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "
SELECT * FROM db_table
WHERE Nom LIKE '%".$search."%'
OR Prenom LIKE '%".$search."%'
OR City LIKE '%".$search."%'
";
}
else
{
$query = "
SELECT * FROM db_table ORDER BY ID";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '<div class="table-responsive">
<table class="table table bordered">
<tr>
<th></th>
<th></th>
</tr>';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td align="center">'.$row["Nom"].'</td>
<td align="center"><input type="submit" value="edit"></td>
</tr>
';
}
echo $output;
}
else
{
echo 'Data Not Found';
}
?> |
merci