使用mysql查询生成大型html表非常慢 - 4000多行查询

时间:2014-01-19 02:45:29

标签: html mysql

在我发送请求后3分钟创建表数据库数据库表中有大约4000条记录,我认为可以通过JavaScript解决,但我不知道如何解决。谢谢

 $query = "SELECT * FROM tblRazduzeniUgovori";
 if ($result = mysqli_query($con, $query)) {
     while($row = mysqli_fetch_array($result))
     {
           echo "<tr>";
           echo "<td><input type='checkbox' name='brojUgovora[]' value='" . $row['Broj'] . "'/></td>";
           echo "<td style='font-size:15px;'>" . $row['Broj'] . "</td>";
           echo "<td>" . $row['Kontrolni_Broj'] . "</td>";
           echo "<td><span class='label label-success' style='width:90%;'>";
           foreach ($kor_id as $key => $val) {
                    if ($val == $row['Korisnik_ID']) {
                        echo $kor_ime[$key] . " " . $kor_prezime[$key];
                        break;
                        }
                    }
           echo "</span></td>";
           echo "<td>" . $row['Datum_Razduzenja'] . "</td>";
           echo "<td>" . $row['Ime_Kupca'] . "</td>";
           echo "<td>" . $row['Ime_Prodavca'] . "</td>";
           echo "<td>" . $row['Cijena'] . " KM</td>";
           echo "<td style='padding:6px;'><span class='label label-         info' style='width:90%; text-align:center;'><a href='/crm/ugovori/" . $row['Slika'] . "' style='color:white;'>" . $row['Slika'] . "</a></span></td>";
           echo "</tr>";
     }
     }
  mysqli_close($con);
  return $vrati;
  }

1 个答案:

答案 0 :(得分:0)

首先将您的查询缩小为仅询问您想要的表格字段,例如:

$query = "SELECT Broj,Kontrolni_Broj FROM tblRazduzeniUgovori "

(显然,将所需的其他字段添加到选择中)

第二次使用连接,而不是吨的回声。

$query = "SELECT * FROM tblRazduzeniUgovori";
$output = '';
 if ($result = mysqli_query($con, $query)) {
     while($row = mysqli_fetch_array($result))
     {
           $output .= "<tr>";
           $output .= "<td><input type='checkbox' name='brojUgovora[]' value='" . $row['Broj'] . "'/></td>";
           $output .= "<td style='font-size:15px;'>" . $row['Broj'] . "</td>";
           $output .= "<td>" . $row['Kontrolni_Broj'] . "</td>";
           $output .= "<td><span class='label label-success' style='width:90%;'>";
           foreach ($kor_id as $key => $val) {
                    if ($val == $row['Korisnik_ID']) {
                        $output .= $kor_ime[$key] . " " . $kor_prezime[$key];
                        break;
                        }
                    }
           $output .= "</span></td>";
           $output .= "<td>" . $row['Datum_Razduzenja'] . "</td>";
           $output .= "<td>" . $row['Ime_Kupca'] . "</td>";
           $output .= "<td>" . $row['Ime_Prodavca'] . "</td>";
           $output .= "<td>" . $row['Cijena'] . " KM</td>";
           $output .= "<td style='padding:6px;'><span class='label label-         info' style='width:90%; text-align:center;'><a href='/crm/ugovori/" . $row['Slika'] . "' style='color:white;'>" . $row['Slika'] . "</a></span></td>";
           $output .= "</tr>";
     }
     }
  mysqli_close($con);
    echo $output;
  }