Получение предупреждений и ошибок при попытке войти в мой сайт с использованием MySQLi и PHP [duplicate]

Вы можете сделать это с событиями перехода, так что вы так и есть, вы создаете 2 класса css для перехода, один из которых содержит анимацию другой, удерживая дисплей в состоянии none. и вы переключаете их после окончания анимации? В моем случае я могу отображать div снова, если я нажимаю btn и удаляю оба класса.

Попробуйте отрезать ниже ...

$(document).ready(function() {
  //assign transition event
  $("table").on("animationend webkitAnimationEnd", ".visibility_switch_off", function(event) {
    //we check if this is the same animation we want  
    if (event.originalEvent.animationName == "col_hide_anim") {
      //after the animation we assign this new class that basically hides the elements.    
      $(this).addClass("animation-helper-display-none");
    }

  });

  $("button").click(function(event) {

    $("table tr .hide-col").toggleClass(function() {
      //we switch the animation class in a toggle fashion...
      //and we know in that after the animation end, there is will the animation-helper-display-none extra class, that we nee to remove, when we want to show the elements again, depending on the toggle state, so we create a relation between them.
      if ($(this).is(".animation-helper-display-none")) {
        //im toggleing and there is already the above classe, then what we want it to show the elements , so we remove both classes...        
        return "visibility_switch_off animation-helper-display-none";
      } else {
        //here we just want to hide the elements, so we just add the animation class, the other will be added later be the animationend event...        
        return "visibility_switch_off";
      }

    });

  });

});
table th {
  background-color: grey;
}

table td {
  background-color: white;
  padding:5px;
}

.animation-helper-display-none {
  display: none;
}

table tr .visibility_switch_off {
  animation-fill-mode: forwards;
  animation-name: col_hide_anim;
  animation-duration: 1s;
}

@-webkit-keyframes col_hide_anim {
  0% {opacity: 1;}
  100% {opacity: 0;}
}

@-moz-keyframes col_hide_anim {
  0% {opacity: 1;}
  100% {opacity: 0;}
}

@-o-keyframes col_hide_anim {
  0% {opacity: 1;}
  100% {opacity: 0;}
}

@keyframes col_hide_anim {
  0%   {opacity: 1;}
  100% {opacity: 0;}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <theader>
    <tr>
      <th>Name</th>
      <th class='hide-col'>Age</th>
      <th>Country</th>
    </tr>
  </theader>
  <tbody>
    <tr>
      <td>Name</td>
      <td class='hide-col'>Age</td>
      <td>Country</td>
    </tr>
  </tbody>
</table>

<button>Switch - Hide Age column with fadeout animation and display none after</button>

12
задан TylerH 13 October 2015 в 19:09
поделиться

3 ответа

Как уже упоминалось в комментариях, это проблема определения. В частности, $con не входит в объем вашей функции getPosts.

Вы должны передать свой объект соединения в качестве зависимости, например

function getPosts(mysqli $con) {
    // etc

Я также очень рекомендую прекратить выполнение, если ваше соединение не удалось. Что-то вроде этого должно быть достаточным

$con=mysqli_connect("localhost","xxxx","xxxx","xxxxx");
if (mysqli_connect_errno()) {
    throw new Exception(mysqli_connect_error(), mysqli_connect_errno());
}

getPosts($con);
21
ответ дан Phil 26 August 2018 в 11:35
поделиться

Функция getPosts(), кажется, ожидает, что $con будет глобальной, но вы не объявляете ее как таковой.

Многие программисты рассматривают лысые глобальные переменные как «запах кода». Альтернатива на другом конце шкалы - это всегда передавать ресурс соединения. Промежуток между ними - это однотонный вызов, который всегда возвращает один и тот же дескриптор ресурса.

0
ответ дан staticsan 26 August 2018 в 11:35
поделиться

используйте глобальную область действия для вашего $ con и помещаем ее в вашу функцию getPosts () следующим образом.

function getPosts() {
global $con;
$query = mysqli_query($con,"SELECT * FROM Blog");
while($row = mysqli_fetch_array($query))
    {
        echo "<div class=\"blogsnippet\">";
        echo "<h4>" . $row['Title'] . "</h4>" . $row['SubHeading'];
        echo "</div>";
    }
}
5
ответ дан user3169490 26 August 2018 в 11:35
поделиться
Другие вопросы по тегам:

Похожие вопросы: