Alucard
Alucard

Reputation: 1902

php - display a table row by row

I print my table like that:

print $tableHeader . $dataRow . $tableFooter;

the $dataRow is the result of a loop (getting data from DB and building the row, nothing unusual), it's something like:

while ($obj = mysql_fetch_object($res)) { 
  $dataRow .= ' <td width="210" style="...">' . $obj->title . ' <br /> '. $obj->screenName .' </td>';
  ...
  ...
}

The problem is when there is a huge amount of information to handle => huge amount of rows to build before displaying the final table.

How could I tell Apache to display it row by row ?

Upvotes: 0

Views: 111

Answers (2)

user2219905
user2219905

Reputation: 38

You could do it with Ajax.

  1. You can make a pagination. When you click on a page, you load only the x results.
  2. You can trigger the user's scroll and load more results.

I personnally use DataTables which can do the two things : http://www.datatables.net/

Hope that helps !

Upvotes: 1

Dvid Silva
Dvid Silva

Reputation: 1162

Can't you paginate?

the way to go is to tell php to display piece by piece, but you will have to change your code a bit to something like.

print $tableHeader 
while ($obj = mysql_fetch_object($res)) { 
   print ' <td width="210" style="...">' . $obj->title . ' <br /> '. $obj->screenName .' </td>';
  flush();
}
print $tableFooter;

Upvotes: 0

Related Questions