Показать сообщение отдельно
  #1 (permalink)  
Старый 31.03.2019, 18:10
Интересующийся
Отправить личное сообщение для Volun Посмотреть профиль Найти все сообщения от Volun
 
Регистрация: 24.03.2019
Сообщений: 21

Vue + Axios + PHP + MySQL
Друзья, прошу вашей помощи. Никак не получается настроить поиск по тексту. Поиск по численным значениям работает нормально, а вот текст не выдает. Код элемента Vue:

var app = new Vue({
  el: '#myapp',
  data: {
    users: "",
    searchtext: "",
    select: "",
  },
  methods: {
    allRecords: function(){

      axios.get('ajaxfile.php')
      .then(function (response) {
         app.users = response.data;
      })
      .catch(function (error) {
         console.log(error);
      });
    },
    recordByID: function(){

      if(this.searchtext >0){
 
        axios.get('ajaxfile.php', {
           params: {
             searchtext: this.searchtext,
             select: this.select,
           }
        })
        .then(function (response) {
           app.users = response.data;
        })
        .catch(function (error) {
           console.log(error);
        });
      }
    }
  }
})


Код файла PHP который принимает запросы от Vue:

<?php
include "config.php";

if (isset($_GET['select'])) { 
  $sel = $_GET['select'];
}

if ($sel = "Signups table") {


$condition = "1";
 if(isset($_GET['searchtext'])){
    $condition = " first_name=".$_GET['searchtext'];
}

$userData = mysqli_query($con,"select * from users WHERE ".$condition);

$response = array();


while($row = mysqli_fetch_assoc($userData)){

   $response[] = $row;
}

echo json_encode($response);
exit;
}

if ($sel = "Leads table") {

$condition = "1";
if(isset($_GET['searchtext'])){
   $condition = " first_name=".$_GET['searchtext'];
}

$userData = mysqli_query($con,"select * from members WHERE ".$condition);

$response = array();


while($row = mysqli_fetch_assoc($userData)){

   $response[] = $row;
}

echo json_encode($response);
exit;
}
?>
Ответить с цитированием