472,782 Members | 1,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 software developers and data experts.

Why is this script so slow?

This script runs fine, but I'd like to know why it's so slow.. Thanks
for any help out there on how i can make it faster (it might take up
to 5 min to write these 3 export files whith 15 records each!!!)

Dan
====================
<style>
body, table, tr, td {
font-family: 'verdana';
font-size: 12px;
}
td.header {
font-weight: bold;
background-color: #cccccc;
}
</style>
</head>
<body>
<br><br><br><br><center>Creating Export Files<br><br>Please be
patient.</center><br><Center>
<?
flush();
$db = mysql_connect("localhost", "stickerguy", "PASWORDHERE!");
mysql_select_db("stickerguy",$db);

// Create contact.tab which is a tab delimated list of customer
numbers names, address, email
// order write old file

// Open contact.tab
$file_name = "/home/biz/stickerguy/WWW/stickerguyadmin/contact.tab";
$logfile = fopen($file_name, "w+") or die("Couldn't create new
file");
echo "<br>contact.tab ";
flush();

// Get all customer numbers
$results = mysql_query("SELECT DISTINCT custnumber.ID AS
customer_number, orders.custid FROM orders, custnumber WHERE
orders.custid = custnumber.scratch AND imported = 0 AND (STATUS =
'payment received' OR STATUS = 'paypal billing complete') ORDER BY
custnumber.ID", $db);

while ($custnumber = mysql_fetch_array($results)) {

$results2 = mysql_query("SELECT * from customer where custid =
".$custnumber["custid"]);
$customer = mysql_fetch_array($results2);

fwrite($logfile, $custnumber["customer_number"]."\t".$customer["name"]."\t".$customer["company"]."\t".$customer["address"]."\t".$customer["state"]."\t".$customer["zip"]."\t".$customer["email"]."\n");

echo ".";
flush();

}
fclose($logfile);

// Create phone.tab which is a tab delimated list of customer numbers
and phone numbers
// over write old file

// Open phone.tab
$file_name = "/home/biz/stickerguy/WWW/stickerguyadmin/phone.tab";
$logfile = fopen($file_name, "w+") or die("Couldn't create new
file");

echo "<br>phone.tab .";
flush();

// Get all customer numbers
$results = mysql_query("SELECT DISTINCT custnumber.ID AS
customer_number, orders.custid FROM orders, custnumber WHERE
orders.custid = custnumber.scratch AND imported = 0 AND (STATUS =
'payment received' OR STATUS = 'paypal billing complete') ORDER BY
custnumber.ID", $db);

while ($custnumber = mysql_fetch_array($results)) {

$results2 = mysql_query("SELECT * from customer where custid =
".$custnumber["custid"]);
$customer = mysql_fetch_array($results2);

if ($customer["phone"] != "") {
fwrite($logfile,
$custnumber["customer_number"]."\t".$customer["phone"]."\tHOME\n");
}
if ($customer["fax"] != "") {
fwrite($logfile,
$custnumber["customer_number"]."\t".$customer["fax"]."\tFAX\n");
}

echo ".";
flush();

}
fclose($logfile);

// Create order list HTML file

// Open orderlist.html
$file_name = "/home/biz/stickerguy/WWW/stickerguyadmin/orderlist.html";
$logfile = fopen($file_name, "w+") or die("Couldn't create new
file");

echo "<br>orderlist.html .";
flush();

fwrite($logfile, "<html>\n<head>\n<title>Order List</title>\n");
fwrite($logfile, "<style>\n");
fwrite($logfile, "td {font-family: Verdana; font-size: 10px;}\n");
fwrite($logfile, "td.leftbox { font-family: Verdana; font-size:
10px; background-color: #E8E8E8; }\n");
fwrite($logfile, "td.box1 { font-family: Verdana; font-size: 10px;
background-color: #CCCCCC }\n");
fwrite($logfile, "td.box2 { font-family: Verdana; font-size: 10px;
background-color: #EEEEEE; }\n");
fwrite($logfile, "</style></head><body>\n");

// Get list of all needed customer numbers for order list
$results = mysql_query("SELECT DISTINCT custnumber.ID AS
customer_number, custnumber.grandtotal, orders.custid FROM orders,
custnumber WHERE orders.custid = custnumber.scratch AND imported = 0
AND (STATUS = 'payment received' OR STATUS = 'paypal billing
complete') ORDER BY custnumber.ID", $db);

// Loop thru customer number building table each time
while ($custnumber = mysql_fetch_array($results)) {

$results2 = mysql_query("SELECT * from customer where custid =
".$custnumber["custid"]);
$customer = mysql_fetch_array($results2);

$results3 = mysql_query("select * from orders where custid =
".$custnumber["custid"]);
$order = mysql_fetch_array($results3);

fwrite($logfile, "<table cellspacing=2 cellpadding=2 width=750
height=185 border=0>\n");
fwrite($logfile, "<tr>");

fwrite($logfile, "<td rowspan=3 class=leftbox
valign=top><b>Customer
#".$custnumber["customer_number"]."</b><br><br>".$order["orderdate"]."<BR><BR>".$customer["name"]."<br>".$customer["address"]."<br>".$customer["city"].",
".$customer["state"]."<BR>".$customer["zip"]."<BR><BR>".$customer["email"]."<BR>ph:
".$customer["phone"]."<br>fx: ".$customer["fax"]."</td>\n");

fwrite($logfile, "<td class=box1>\n");

fwrite($logfile, "<table cellpadding=2 border=0 width=100%>\n");

fwrite($logfile, "<tr>\n");
fwrite($logfile, "<td><b>Payment Method:</b></td>\n");
if ($order["status"] == "paypal billing complete") {
fwrite($logfile, "<td>Pay Pal</td>\n");
}
if ($order["status"] == "payment received") {
fwrite($logfile, "<td>Check/Mail</td>\n");
}
fwrite($logfile, "<td><b>Payment Amount:</b></td>\n");
fwrite($logfile, "<td>$".$custnumber["grandtotal"]."</td>\n");
fwrite($logfile, "</tr>\n");

fwrite($logfile, "<tr>\n");
fwrite($logfile, "<td><b>Requested Deadline:</b></td>\n");
fwrite($logfile, "<td colspan=3>".$order["deadline"]."</td>\n");
fwrite($logfile, "</tr>\n");

fwrite($logfile, "</table>\n");

fwrite($logfile, "</td>\n");

fwrite($logfile, "<tr><td class=box2>\n");

fwrite($logfile, "<table cellpadding=2 border=0 width=100%>\n");
$results4 = mysql_query("select * from orders where custid =
".$custnumber["custid"]);
while($orders = mysql_fetch_array($results4)) {

fwrite($logfile, "<tr>\n");
fwrite($logfile, "<td><b>".$orders["project"]."</b></td>\n");
fwrite($logfile, "<td>".$orders["quantity"]."
".$orders["ordertype"]." ".$orders["size"]."</td>\n");
fwrite($logfile, "<td>\n");
if ($orders["vinyl"] != "") {
fwrite($logfile, "Vinyl: ".$orders["vinyl"] . " "); }
if ($orders["color1"] != "") {
fwrite($logfile, "Color1: ".$orders["color1"] . " "); }
if ($orders["color2"] != "") {
fwrite($logfile, "Color2: ".$orders["color2"] . " "); }
if ($orders["color3"] != "") {
fwrite($logfile, "Color3: ".$orders["color3"] . " "); }
if ($orders["color4"] != "") {
fwrite($logfile, "Color4: ".$orders["color4"] . " "); }
fwrite($logfile, "</td>\n");
fwrite($logfile, "<td>Artwork ".$orders["os"]."
".$orders["software"] . " " . $orders["filename"] . "</td>\n");
fwrite($logfile, "</tr>\n");
}
mysql_query("update orders set imported = 1 where custid =
".$custnumber["custid"]);

fwrite($logfile, "</table>\n");
fwrite($logfile, "</td></tr>\n");

fwrite($logfile, "<Tr><td class=box1>" . $customer["notes"] .
"</td></tr>\n");
fwrite($logfile, "</table>\n");

fwrite($logfile, "<hr color=black width=750>\n");

echo ".";
flush();

}

fwrite($logfile, "</body></html>");



// Output links to each of the above 3 files.
?>
</center>
<Br><br>
<center>
<a target="new" href="contact.tab">contact.tab</a><br>
<a target="new" href="phone.tab">phone.tab</a><br>
<a target="new" href="orderlist.html">orderlist.html</a><br>
<Br><br>
Right click the above links and click "save as" or "save target as" to
save the files. <Br><Br>
Orders have been marked as processed.

</center>
</body>
</html>
Jul 16 '05 #1
0 3202

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Shay | last post by:
essentially I am trying to do some counts based on some assumptions in the recordset. So I get the RS back, put the values into a variable, move to the next record in the RS and compare what is in...
4
by: Schraalhans Keukenmeester | last post by:
I have no clue why below code (found it somewhere and altered it a wee bit to my needs) will run without problem in both IE and Mozilla FireFox 1.0 but in the latter it takes up close to 100% cpu....
4
by: trint | last post by:
Ok, This script is something I wrote for bringing up a report in reporting services and it is really slow...Is their any problems with it or is their better syntax to speed it up and still provide...
19
by: octangle | last post by:
This code is attempting to find records that have a RegJrnID that does not occur more than one time in the table. The reason that I want to find records with non-duplicated RegJrnID values is to...
0
by: Yong Wang | last post by:
Hi, All: I have written a python CGI script to run in html web page. When I access to the html page, it only runs part of the script, then abort because the late part of the script is involved in...
0
by: FFMG | last post by:
First I should point out, that 99.99% of the time I have no problems with my server. Yes, it is semi busy but nothing that should bring MySQL server down. I get on average 70 to 100 queries a...
1
by: Webber | last post by:
hi, I am searching for a script to use in access vb script, to convert/upload the access db to mysql there are serveral converters, but I use something that can build in in the script. the...
4
by: melmack3 | last post by:
Hello My PHP script executes many bash/cmd commands. Functions like "exec()" or "system()" cause that new bash/cmd session is started, the command is executed and the session is closed....
7
by: jeddiki | last post by:
Hi, As I am in Turkey at present, I can not see vidoes on youtube. So I have tried a few proxies but keep finding them slow or not working. So I have installed myphpProxy on my server under...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.