By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,082 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,082 IT Pros & Developers. It's quick & easy.

Why is this script so slow?

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.