duandou1903 2016-01-06 18:58
浏览 44
已采纳

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

Im using ajax to print the dates from my database.

The problem is that i dont see the last tuple of my database. So if there is only one tuple in my database , I do not see even this (Because is the last).

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>
     ';
    }


}                   
?>

Thanks all.

  • 写回答

1条回答 默认 最新

  • douguanya4248 2016-01-06 19:05
    关注

    You are loosing a row each time you call this function by calling $array = mysql_fetch_row($sql); before you start your while loop.

    <?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>';
        }
    }                   
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出