我没看到ajax的最后一次调用

时间:2016-01-06 18:58:08

标签: php jquery mysql ajax database

我使用ajax从我的数据库中打印日期。

问题是我没有看到我的数据库的最后一个元组。 因此,如果我的数据库中只有一个元组,我甚至都看不到(因为是最后一个)。

的Ajax

$(function update ()  {
      $.ajax({       
      type: "POST",
      url: '/includes/contenuto.php',                  //the script to call to get data  
      data:{action:"show"},   
      success: function(data)          //on recieve of reply
      { 
        $("#pinBoot").html(data);
      }


        }).then(function() {           // on completion, restart
       setTimeout(update, 5000);  // function refers to itself
    });
      });

PHP

<?php
include('../core.php');
$action=$_POST["action"];
if($action=="show"){
$sql = mysql_query("")  or die ("Nessun errore");

$array = mysql_fetch_row($sql); 
    while ($row = mysql_fetch_array($sql))
    {
        echo '
    <article class="white-panel">
        <h4><a href="#">'.$row ['titolo'].'</a></h4>
        <p>'.Markdown($row ['contenuto']).'</p>
      </article>
     ';
    }


}                   
?>

谢谢大家。

1 个答案:

答案 0 :(得分:3)

每次调用此函数时,在开始while循环之前调用$array = mysql_fetch_row($sql);,就会失去一行。

<?php
include('../core.php');
$action=$_POST["action"];
if($action=="show"){
    $sql = mysql_query("SELECT `id`, DATE_FORMAT(data,'%e %b %Y') AS 
                       `data`, AES_DECRYPT(unhex(contenuto),'PASSWORD') AS 'contenuto', 
                       `video`, aes_decrypt(unhex(titolo),'PASSWORD') AS 'titolo', 
                       `immagine` 
                       FROM `post` 
                       WHERE 1 
                       ORDER by id DESC")  or die ("Nessun errore");

    // READ AND IGNORE A ROW? WHY
    //$array = mysql_fetch_row($sql); 

    while ($row = mysql_fetch_array($sql))
    {
        echo '
        <article class="white-panel">
            <h4><a href="#">'.$row ['titolo'].'</a></h4>
            <p>'.Markdown($row ['contenuto']).'</p>
        </article>';
    }
}                   
?>
相关问题