473,411 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 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 3252

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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.