Hello my database query very slow. 5 minutes for listing 4000 rows in html table... Please help.
**$query = "SELECT * FROM tblRazduzeniUgovori WHERE Status='razduzen'";**
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>";
Thanks you.
First: add status as an index on the database table, this will speed up the select portion of the script.
Second: concatenate the string, rather than issuing an echo statement each time, echo * 4000 can be quite slow.
$query = "SELECT * FROM tblRazduzeniUgovori WHERE Status='razduzen'";
$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>";
}
}
echo $output;
this might not be what you're looking for, but i suggest not to show so many rows, you can limit :)
<?php
$displayed_items = 100; // items displayed per page
$start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
$end = $start + $displayed_items;
$query = "SELECT * FROM tblRazduzeniUgovori
WHERE Status='razduzen' LIMIT {$start}, {$end}";
?>
<table>
<?php
if ($result = mysqli_query($con, $query)) {
while($row = mysqli_fetch_array($result)): ?>
<tr>
<?php foreach ($a as $row):?>
<td>
<?php echo $a ?>
</td>
<?php endforeach; ?>
</tr>
<?php endwhile; ?>
</table>
<form action='#' method='get'>
<input type='hidden' name='start' value='<?php echo $start + $displayed_items ?>' />
<input type='submit' value='next page' />
</form>
like that you can see results just bu clicking next, dont forget to add ORDER BY to the query