tags:

views:

65

answers:

1

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  A: 

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"].

Amarghosh
Thanks Amarghosh but please don't punish me for making this post a community wiki, by not spending time to add some code to your answer :)
baltusaj
updated the post.
Amarghosh
Thanks a million Amarghosh. Now, updating my code according to your suggestion, even though i won't always know, in advance, the number of rows in the table being accessed from a database.
baltusaj
14 questions and 0 votes : Do you know how stack overflow work? http://meta.stackoverflow.com/questions/7237/how-does-reputation-work-on-stackoverflow/7238#7238
Amarghosh
I guess so...Went through the link you mentioned. I think i will get votes only if i answer some question. And if i don't, my reputation will not go down :)But i will like it to increase for sure. And whenever i come across some question whose ans i know i will definitely reply to it.
baltusaj
You are right: You answer questions, people find them helpful and vote you up and you gain reps. Now, ever wondered how those people (who answer your questions) gain reps...?
Amarghosh
I guess what I am trying to remind you is that despite having asked 15 questions with many accepted answers you have never cast a single vote so far. Consider going back to your questions and clicking the up arrow button near the helpful answers - that's how they gain reps.
Amarghosh
May be you were not aware of this thing at all - but people may find this as a hostile attitude and ignore your questions.
Amarghosh
That is all good for getting the rows starting at an index, but if the datagrid is sorted you are now out of luck so you will have to make sure to add a sort property to your call.
AndrewB
@Andrew Yeah, the query should account for required sorting
Amarghosh