how do i fix my php application making browser unresponsive

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
morenatoxx
Forum Newbie
Posts: 1
Joined: Tue Jan 10, 2017 7:50 am

how do i fix my php application making browser unresponsive

Post 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> 
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

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

Post 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
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

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

Post 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.
Warning: I have no idea what I'm talking about.
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

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

Post 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>
Warning: I have no idea what I'm talking about.
Post Reply