Guest User

Untitled

a guest
Jun 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <?php
  2. $service = '';
  3. $query = "SELECT service FROM services GROUP BY service";
  4. $result = mysqli_query($con, $query);
  5. while($row = mysqli_fetch_array($result))
  6. {
  7. $service .= '<option
  8. value="'.$row["service"].'">'.$row["service"].'</option>';
  9. }
  10. ?>
  11.  
  12. <select name="service" id="service" class="form-control action">
  13. <option value="">Выберите тип услуги</option>
  14. <?php echo $service; ?>
  15. </select>
  16.  
  17. <?php
  18. $sql = "SELECT service FROM services GROUP BY service";
  19. $result = mysqli_query($con, $query);
  20. $service = array();
  21. while($row = mysqli_fetch_array($result)){
  22. $service[] = $row;
  23. }
  24. echo json_encode($service, JSON_UNESCAPED_UNICODE);
  25. ?>
  26.  
  27. $(function(){
  28. function selectUpdate() {
  29. $.ajax({
  30. url: 'service.php',
  31. async:false,
  32. success: function(data){
  33. json = JSON.parse(data);
  34. for (i = 0; i < json.length; i++)
  35. $('#service').append('<option value="'+json[i].service+'">'+json[i].service+'</option>');
  36. }
  37. });
  38. }
  39. selectUpdate();
  40. $('#service').on('change', function(){
  41. selectUpdate();
  42. });
  43. });
Add Comment
Please, Sign In to add comment