doucan8521 2009-10-29 02:59
浏览 35
已采纳

在DataGrid中逐个显示从数据库中提取的行

I have a table (session) in a database which has almost 72,000 rows. I extract those rows with the help php+mysql but when the result is returned to the HTTPService, i need to wait for some 32 seconds before the all the rows start appearing in the DataGrid at once.

Question Is there any way by which DataGrid may start displaying data one by one while the application may extract next rows in parallel. Or that the DataGrid may show data in chunks of hundreds. Like when application starts, it may show first 400 enteries in DataGrid, then the next 400 hundred are extracted until all the 72,000 rows are extracted?

Or can i involve threading such that one thread may be responsible for displaying data in datagrid while the other, executing in parallel may be responsible for extracting next data from database?

Thanks a lot guys as always.

<mx:HTTPService id="populateTable" url="request.php" method="POST"  resultFormat="e4x">
     <mx:request xmlns="">
        <getResult>table</getResult>
     </mx:request>
</mx:HTTPService>

code from PHP file

function populateTable()
{
   $Result = mysql_query("SELECT * FROM session" );

   $Return = "<Sessions>";
   while ( $row = mysql_fetch_object( $Result ) )
   {
     $Return .= "<session><no>".$no."</no>" . 
                "<srcIP>".$row->srcIP."</srcIP>" .
               "<dstIP>".$row->dstIP."</dstIP>" .
                "<sPort>".$row->sPort."</sPort>" .
                "<dPort>".$row->dPort."</dPort>" .
                "<sessionID>".$row->sessionID."</sessionID>" .
                "<numberOfConnections>".$row->numberOfConnections."</numberOfConnections>" .
                "</session>";
   }
     $Return .= "</Sessions>";
  // mysql_free_result( $Result );

   echo $Return;
}
  • 写回答

1条回答 默认 最新

  • dtbsezxw28056 2009-10-29 04:26
    关注

    Consider redesigning the app. No sane user is gonna need to see the whole 72K of data at the same time.

    • Change the php script so that it accepts a startIndex parameter and selects 100 rows from that index instead of selecting *.
    • Add Next page/Previous page buttons in the flex app that causes HTTPService to be resend with changed startIndex value. Bind the lastResult of the HTTPService to the DataGrids dataProvider.

    Update:

    <mx:HTTPService id="service" resultFormat="e4x"/>
    <mx:DataGrid dataProvider="{service.lastResult}">
      <!-- columns -->
    </mx:DataGrid>
    <mx:Button label="Next" click="next()"/>
    <mx:Button label="Prev" click="prev()"/>
    <mx:Script>
      <![CDATA[
        private var currentIndex:Number = 0;
        private var itemsPerPage:Number = 100;
        private var total:Number = 72000;
        private function next():void
        {
          if(currentIndex + 1 >= total/itemsPerPage)
            return;
          currentIndex++;
          service.url = "request.php?page=" + currentIndex;
          service.send();
        }
        private function prev():void
        {
          if(currentIndex == 0)
            return;
          currentIndex--;
          service.url = "request.php?page" + currentIndex;
          service.send();
        }
      ]]>
    </mx:Script>
    

    Here I've appended the index to the url itself. You may also use the request property of HTTPService to send the data.

    In php, change the query "SELECT * FROM session" so that it selects only 100 queries based on the value of $_GET["page"].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行