Page 1 of 1

really slow page load?

Posted: Thu Aug 19, 2004 3:32 pm
by jglicken
feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

<?php
session_start();
require("config.php");
include("header.php");

// convert username and password from _POST or _SESSION
if($_POST["username"])
{
  $username=$_POST["username"];
  $secret=$_POST["secret"];
}
elseif($_SESSION["username"])
{
  $username=$_SESSION["username"];
  $secret=$_SESSION["secret"];
}

// start and register session variables
session_register("username");
session_register("password");

//Get the value of the variable sent from pull down along with hidden variable
$os = $_GET["os"];
if(!(isset($os))) {
        $os = $_POST["os"];
}
$date = $_GET["date"];
if(!(isset($date))) {
        $date = $_POST["date"];
}
//query for total cost for month
$mthlycost=mysql_query("select sum(format((a.billsec/60 * b.rate), 2)) totald from cdr a
                    left join rates b on a.dst like '1%' = b.destination where dst like '1%'
                    and src='$username' and calldate like '$date%'
                    order by 'calldate' desc")
        or die ("Cannot get total".mysql_error());

while($row = mysql_fetch_array($mthlycost))
{
$mthtotal = $row['totald'];
}

//query for total minutes for month
$mthlymin=mysql_query("select sec_to_time(sum(billsec)) as domtotal from cdr
                       where src='$username' and dst like '1%' and length(dst) != '4'
                       and calldate like '$date%'")
        or die ("MySQL error".mysql_error());

while($row = mysql_fetch_array($mthlymin))
{
$mthmins = $row['domtotal'];
}
//query for data selected by month
$mthly=mysql_query("select a.calldate, a.src, a.dst, b.name, sec_to_time(a.billsec) as billsec,
                       format((a.billsec/60 * b.rate), 2) totalcost from cdr a
                       left join rates b on a.dst like '1%' = b.destination where dst like '1%'
                       and src='$username' and calldate like '$date%' order by 'calldate' desc")
       or die ("No Domestic calls made for the month selected");


//display the pull down menu
print"       <table align=center border=0>
             <td align=center><br><br><br>
               <FONT size=1><b>Please choose the month you want to view</b></FONT>
               <form METHOD=post NAME=theForm action=> <input TYPE=submit value=search>
               <input type=hidden name=os value=ds>
               <select name=date size=1>
               <option selected>Month</option>
               <option value=2004-01>January</option>
               <option value=2004-02>February</option>
               <option value=2004-03>March</option>
               <option value=2004-04>April</option>
               <option value=2004-05>May</option>
               <option value=2004-06>June</option>
               <option value=2004-07>July</option>
               <option value=2004-08>August</option>
               <option value=2004-09>September</option>
               <option value=2004-10>October</option>
               <option value=2004-11>November</option>
               <option value=2004-12>December</option>
               </select>
               </form></P>
             </td>
           </table>";


//output for data selected monthly
if ($os=="ds")
{
$mthnum = mysql_num_rows($mthly);
if ($mthnum !=0)
{
//        print "<CENTER><H3>You have $julynum International calls for for the month of July for a total of $julymins
//                           <BR>for a charge of $$julytotal";
        print "<center></H3><br><TABLE border=0 cellspacing=2><tr font size=1 bgcolor=#6699ff>
                            <th>Date & Time<th>Dialed Number<th>Destination<th>Duration<th>Total Cost\n";
        for ($j=0; $j < $mthnum; $j++)
        {
                $row = mysql_fetch_array($mthly);
                print "<tr bgcolor=white><td align=cneter width=275>" . $row['calldate'];
                print "<td align=left width=200>" . $row['dst'];
                print "<td align=left width=250>" . $row['name'];
                print "<td align=center width=100>" . $row['billsec'];
                print "<td align=right width=100>$" . $row['totalcost'];
                print "\n";
        }
        print"</table>\n";
        print"<center><table width=956 border=0>
                <tr>
                  <td>
                    <table align=right border=0><tr bgcolor=#6699ff><td align=center width=100>$mthmins</td>
                       <td align=right width=100>$$mthtotal</td></tr></table>
                  </td>
                </tr>
              </table></center>\n ";
}
else    print "<center><b><font size=3 color=red>No Domestic calls made for the selected month by  " . $username;
print"</table></center>\n";
}

?>
it takes almost 3-5 minutes to load this page?
am i doing something wrong here. I have similar pages that take just as long, but this will do for an example. i log into my site with a user that has about 9000 records total, and maybe just a couple hudred when i run the query.

any suggestions would be appreiciated


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Thu Aug 19, 2004 3:48 pm
by jglicken
sorry, my bad. won't happen again.

thanks,
jason

Posted: Fri Aug 20, 2004 5:55 pm
by William
Try using: mysql_close();

Posted: Mon Aug 23, 2004 10:45 am
by jglicken

Code: Select all

Try using: mysql_close();
i'm not sure where to use this to help me with page load time?
could you be a little more specific?

thanks,
jason