very slow table generation

Hi,

I need help with my first php project. I display some information about my customers in various lists, and when the database grows the time it takes to load these pages increases rapidly. With about 150 customers it takes almost 8 seconds for the page to load! Can someone give me a hint what I might do wrong here? When I look at the data base in phpmyadmin, this table with even more info displays instantaneous, but I was unable to analyze the code of that tool to find out what they do differently.
I use a local XAMPP to serve the pages, so it’s not a data transfer problem.

Here’s the relevant piece of the code:

  <div id="KundenDivBody" style="height:6cm; overflow:auto; padding:1px">
    <table id="KundentabelleBody" class="Kundenliste" rules="all">
      <?php
        $abfrage = "SELECT * FROM kunden ORDER BY Nachname";
        $ergebnis = mysql_query($abfrage);
          while($row = mysql_fetch_object($ergebnis))
          {
            echo "<tr".(($row->Aktiv==1) ? " class='Normal'" : " class='Reserviert'")." id='Kunde$row->Kunde'>n";
            echo "<td onclick='editNummer($row->Kunde, "$row->Nachname", "$row->Vorname")'>n";
            echo $row->Kunde."n";
            echo "</td>n";
            echo "<td onclick='editNachname($row->Kunde, "$row->Nachname")'>n";
            echo $row->Nachname."n";
            echo "</td>n";
            echo "<td onclick='editVorname($row->Kunde, "$row->Vorname")'>n";
            echo $row->Vorname."n";
            echo "</td>n";
            echo "<td onclick='javascript:editTelefon($row->Kunde, "$row->Nachname", "$row->Vorname", "$row->Telefon")'>n";
            echo $row->Telefon."n";
            echo "</td>n";
            echo "<td onclick='toggleHelfer($row->Kunde, "$row->Nachname", "$row->Vorname", $row->Helfer)'>n";
            echo (($row->Helfer==1) ? "Ja" : "Nein")."n";
            echo "</td>n";
            echo "<td onclick='toggleAlthelfer($row->Kunde, "$row->Nachname", "$row->Vorname", $row->Althelfer)'>n";
            echo (($row->Althelfer==1) ? "Ja" : "Nein")."n";
            echo "</td>n";
            echo "<td onclick='toggleAktiv($row->Kunde, "$row->Nachname", "$row->Vorname", $row->Aktiv)'>n";
            echo (($row->Aktiv==1) ? "Aktiv" : "Reserviert")."n";
            echo "</td>n";
            echo "<td class='Loeschen' onclick='delKunde($row->Kunde, "$row->Nachname", "$row->Vorname")'>n";
            echo "L?¶schenn";
            echo "</td>n";
            echo "</tr>n";
          }
      ?>
    </table>
  </div>

If I comment out all the echo lines, it’s fast again, so it’s not the data base acces that’s slowing it down. I also tried writing all these lines into a variable and then use a single echo to send it, but that didn’t help.

Thank you in advance for any help you may be able to give me!

Off the top of my head, this might just be the problem:

while($row = mysql_fetch_object($ergebnis)) 

Try using:

while($row = mysql_fetch_row($ergebnis)) 

Please read up on the following articles:

  • mysql_fetch_row()
  • mysql_fetch_array()
  • mysql_fetch_object()

I’m thinking you’re creating objects for your result set, and objects can be resource hogs.

Ok, I’ve tried that. Unfortunately, it didn’t change a thing.
And I tried again with this method to comment out one table row after the other, and with every one it got faster.
But why would these echo commands be so damn slow? That’s 26 echo commands per table row and 140 rows, so a small delay would be understandable, but almost 8 seconds?

I hope someone here can shed some light on this, as I’m completly baffled.

Sponsor our Newsletter | Privacy Policy | Terms of Service