Last active
December 24, 2020 10:07
-
-
Save djoudi/87cffc6e24e530bc757959270f2acacd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once 'inc/config.php'; | |
| $q = (isset($_GET['nom']))?$_GET['nom']:null; | |
| $sql = "SELECT * FROM clients WHERE nom LIKE '%$q%'"; | |
| $res = mysqli_query($connect,$sql) or die(mysqli_error($res)); | |
| $num = mysqli_num_rows($res); | |
| $client = []; | |
| if ($num>0) { | |
| while ($data = mysqli_fetch_array($res)): | |
| $client[] = $data['nom']; | |
| endwhile; | |
| $clientJson = json_encode($client); | |
| echo $clientJson; | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function() { | |
| $(document).on('keyup', 'input[name=search]', function(event) { | |
| event.preventDefault(); | |
| var data = $(this).val() | |
| $.ajax({ | |
| url:'action.php', | |
| type: 'GET', | |
| data: {nom:data}, | |
| beforeSend:function () { | |
| // $("#forms").trigger("reset"); | |
| // $('#btn').text('Loading ...').removeClass('btn-primary').addClass('btn-danger') | |
| }, | |
| success:function(req){ | |
| $("#result").html('') | |
| var reqJson = jQuery.parseJSON(req) | |
| for (var i = 0; i < reqJson.length; i++) { | |
| $("#result").append('<li>'+reqJson[i]+'</li>') | |
| } | |
| console.log(jQuery.parseJSON(req)); | |
| } | |
| }) | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| include 'inc/header.php'; | |
| require_once 'inc/config.php'; | |
| ?> | |
| <div class="container mt-5" > | |
| <div class="row"> | |
| <div class="col-12"> | |
| <div class="form-group"> | |
| <input type="search" name="search" class="form-control" placeholder="Search"> | |
| <ul class="list-unstyled bg-white text-success" id="result"> | |
| </ul> | |
| </div> | |
| </div> | |
| <div class="col-12"> | |
| </div> | |
| </div> | |
| </div> | |
| <?php | |
| include 'inc/footer.php'; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment