Good day, I have billing system that only works when the data in the database is not much but when I import a full items of data into the table the browser freeze and takes a long time to retrieve what I search, I have tried to add limit to my query as suggested here:
MySQL & PHP load more then 1000 items makes browser freeze
but the problem with that is, it does not retrieved all data from the table as its limited.
is there any other workaround that I can try?
Here is my piece of code:
<?php
$query = "SELECT * FROM medications ";
$result = $con->query($query);
?>
<select id="disease" style="width: 40%;" name="disease" required="true" data-toggle="tooltip" data-original-title="medications" class="date-picker form-control col-md-7 col-xs-12" data-rel="chosen">
<option value="">Select Disease</option>
<?php while ($row = $result->fetch_array(MYSQLI_ASSOC)) { ?>
<option value="<?php echo $row['ICD10'] ?>"><?php echo $row['diagnosis']; ?> </option>
<?php } ?>
</select>
If your browser itself freezes, meaning that the whole browser becomes unresponsive, it simply means that your browser itself is running out of capacity (likely due to low RAM on your 'puter). There's not much you can do about that in PHP/MySQL itself. Some things you can try:
data-toggle
attribute. Dynamically applying a ton of events/classes will lead to issues.And if by "freeze" you mean that the script takes a long time to execute... I see you query for all fields in the table, SELECT *
. You can make it lighter for MySQL and your server RAM by only selecting the fields you actually require (SELECT ICD10, diagnosis ...
). Also consider adding in pagination and using (Sorry: That's not relevant here, since you're using the data for LIMIT
in your query.<select>
options.) There's not a whole lot that can be said about your PHP here, but do look around and see if there are possible bottlenecks outside the code snipped you've posted.