Page 1 of 1

how do i fix my php application making browser unresponsive

Posted: Tue Jan 10, 2017 8:07 am
by morenatoxx
good day, i have an application which i have developed in php and myslq but when i populate the database with lots of data(data required by the application) it makes the browser unresponsive and takes longer to execute, can anyone please help me resolve this. I include the code below.M

Code: Select all

<?php 
                     include_once 'dbConfig.php';
                     $query="SELECT * FROM medications";
                     $result= $con->query($query);
                    ?>  
                          <select id="nol" 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>
  <form method="POST" action="generate-invoive-results-service.php">
  <input type="hidden" name="id" value="<?php echo $id;?>">
   
                   <?php  
                     $query="SELECT * FROM medications";
                     $result= $con->query($query);
                    ?>  
                          <select id="nol" style="width: 30%; margin-left: -5%;" name="prescription" 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 Medicatioon</option>
                             <?php while ($row=$result->fetch_array(MYSQLI_ASSOC)) { ?>
                            <option value="<?php echo $row['prescription']?>"><?php echo $row['prescription'];?> </option> 
                      <?php } ?> 
                         </select> 

Re: how do i fix my php application making browser unrespon

Posted: Tue Jan 10, 2017 8:16 pm
by Vegan
how fast is your database and also the server CPU which has to assemble to HTML before the server can send it to the browser

Re: how do i fix my php application making browser unrespon

Posted: Thu Jan 12, 2017 11:34 pm
by thinsoldier
If it's crashing your browser the problem is with what the browser receives in the end.

How many database records do you have?

You're running exactly the same query twice: $query="SELECT * FROM medications";

This could slow down your server's response time but would not be responsible for the browser crashing.

My guess is you have many hundreds or thousands of records in the medications table and that results in 2x that many select options and your browser cannot handle that many DOM nodes in the html document it's trying to render.

Re: how do i fix my php application making browser unrespon

Posted: Thu Jan 12, 2017 11:47 pm
by thinsoldier
This doesn't solve your problem, it's just how I would have arranged the code.

Code: Select all

<?php 
include_once 'dbConfig.php';

$query="SELECT * FROM medications";

$result= $con->query($query);

$allDiagnosis = array();
$allPrescription = array();
while( $row = $result->fetch_array(MYSQLI_ASSOC) )
{
    // Add to diagnosis array - keyed by the ICD10 field
    $allDiagnosis[ $row['ICD10'] ] = $row['diagnosis'];
    
    // Add to prescription array
    $allPrescription[] = $row['prescription'];
}
?> 

<select id="nol" 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 foreach( $allDiagnosis as $ICD10 => $diagnosis) { ?>
    <option value="<?php echo $ICD10;?>"> <?php echo $diagnosis;?> </option> 
   <?php } ?> 
</select>

## I don't understand why the select tag above is not within a form...

<form method="POST" action="generate-invoive-results-service.php">
    <input type="hidden" name="id" value="<?php echo $id;?>">
    <select id="nol" style="width: 30%; margin-left: -5%;" name="prescription" 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 Medication</option>
        <?php foreach( $allPrescription as $prescription) { ?>
        <option value="<?php echo $prescription;?>"> <?php echo $prescription;?> </option> 
        <?php } ?> 
    </select>