Jump to content

js_280

Members
  • Posts

    33
  • Joined

  • Last visited

    Never

Everything posted by js_280

  1. I've been trying to figure out what's wrong with this code for several days now... Running PHP 5.8 on Windows Server 2003 The pdf files are being created correctly, I can go open them with Adobe without a problem. The problem comes when the script attempts to add the pdf file as an attachment. Something is apparently messing with the headers because the pdf file is simply dumped into the email as plain text. Can anyone see something that I've missed? I found the code on devshed and thought it would port over without problem... try { $pdf->end_document(""); $buf = $pdf->get_buffer(); $len = strlen($buf); $filename = rand(0, getrandmax()).".pdf"; file_put_contents($filename, $buf); $to = $branches[$i]['email']; //define the subject of the email $subject = 'Automated Collection Letters for Branch '.$branches[$i]['num']; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: admin@somwhere.com\r\nReply-To: admin@somewhere.com"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; //read the atachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents($filename))); //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Type: application/pdf; name="<?php echo($filename); ?>" Content-Transfer-Encoding: base64 Content-Disposition: attachment <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email mail('someone@somewhere.com', $subject, $message, $headers); } catch(Exception $e) { } This is what I'm getting in the body of the email...
  2. The vendor exports their database via ODBC into MySQL... Anyway...here's what I came up with... SELECT table.Qty, IF(table.Qty REGEXP '-$', (CAST(table.Qty AS DECIMAL) * -1), CAST(table.Qty AS DECIMAL)) AS real_number from table; Probably overly complicated, but it worked...
  3. I have a program that exports columns into a MySQL varchar column. The vendor exports numbers and strings into this column. I'm only pulling the fields that have numbers in them and casting them as decimals. The problem I'm running into is that when the vendor exports the negative numbers, the negative sign comes after the number instead of before and is causing the number to add instead of subtract when SUM()'ng. Any ideas?
  4. I've attempted to try my hand at using PHP and COM in Windows, however I cannot seem to get any of the objects to become visible. For example the following script will not display Excel... $excel = new COM('Excel.Application') or die('Cannot start Excel'); $excel->Visible = true; This script starts an Excel process in task manager, but will not display the program. I've looked through all of my IIS settings and "Allow Service to Interact with Desktop" is checked. I'm at a loss, because if is run this statement... echo($excel->Version); It displays 11.0 which is the version of Excel I am running... Any ideas or suggestions? Something I've overlooked?
  5. Works under my Firefox with substituted url. Use Firebug extension on Firefox to see if you're getting a reply from your script.
  6. js_280

    Slow Query...

    I want to be able to get all customers using the criteria specified without having the customer listed multiple times simply because they have multiple tanks tied to their location. Without the DISTINCT statement, I would get approximately 30,000 duplicates.
  7. js_280

    Slow Query...

    ID's are unique, however there can be multiple tanks tied to each location, and will add duplicates. Indexes: mysql> show indexes from customerfile \G; *************************** 1. row *************************** Table: customerfile Non_unique: 1 Key_name: comp_index Seq_in_index: 1 Column_name: CustomerCompanyNumber Collation: A Cardinality: 90 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: *************************** 2. row *************************** Table: customerfile Non_unique: 1 Key_name: account_index Seq_in_index: 1 Column_name: CustomerNumber Collation: A Cardinality: 296830 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: 2 rows in set (0.00 sec) mysql> show indexes from locationfile \G; *************************** 1. row *************************** Table: locationfile Non_unique: 1 Key_name: locationIDX Seq_in_index: 1 Column_name: LocationCustomerNumber Collation: A Cardinality: 301336 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: *************************** 2. row *************************** Table: locationfile Non_unique: 1 Key_name: productcodeIDX Seq_in_index: 1 Column_name: LocationProductCategory Collation: A Cardinality: 56 Sub_part: NULL Packed: NULL Null: YES Index_type: BTREE Comment: *************************** 3. row *************************** Table: locationfile Non_unique: 1 Key_name: location_company Seq_in_index: 1 Column_name: LocationCompanyNumber Collation: A Cardinality: 91 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: *************************** 4. row *************************** Table: locationfile Non_unique: 1 Key_name: location_locationnumber Seq_in_index: 1 Column_name: LocationNumber Collation: A Cardinality: 1969 Sub_part: NULL Packed: NULL Null: YES Index_type: BTREE Comment: 4 rows in set (0.00 sec) mysql> show indexes from tankfile \G; *************************** 1. row *************************** Table: tankfile Non_unique: 1 Key_name: tank_cust_index Seq_in_index: 1 Column_name: TankChargeToCustomer Collation: A Cardinality: 169650 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: *************************** 2. row *************************** Table: tankfile Non_unique: 1 Key_name: serial_index Seq_in_index: 1 Column_name: TankSerialNo Collation: A Cardinality: 169650 Sub_part: NULL Packed: NULL Null: YES Index_type: BTREE Comment: *************************** 3. row *************************** Table: tankfile Non_unique: 1 Key_name: tank_company Seq_in_index: 1 Column_name: TankCompanyNumber Collation: A Cardinality: 91 Sub_part: NULL Packed: NULL Null: Index_type: BTREE Comment: *************************** 4. row *************************** Table: tankfile Non_unique: 1 Key_name: rental_tank Seq_in_index: 1 Column_name: TankRentalTank Collation: A Cardinality: 3 Sub_part: NULL Packed: NULL Null: YES Index_type: BTREE Comment: 4 rows in set (0.00 sec)
  8. js_280

    Slow Query...

    15.075 seconds without where clauses... SELECT distinct sqlar001.customerfile.customernumber, sqlar001.customerfile.customercompanynumber, sqlar001.customerfile.CustomerStatementName, sqlar001.locationfile.locationnumber FROM sqlar001.customerfile inner join sqlar001.locationfile on sqlar001.customerfile.customernumber = sqlar001.locationfile.locationcustomernumber AND sqlar001.customerfile.customercompanynumber = sqlar001.locationfile.locationcompanynumber inner join sqlar001.tankfile on sqlar001.customerfile.customernumber = sqlar001.tankfile.tankchargetocustomer and sqlar001.customerfile.customercompanynumber = sqlar001.tankfile.tankcompanynumber; [attachment deleted by admin]
  9. js_280

    Slow Query...

    There is a non-unique index on customerfile.customernumber, locationfile.locationcustomernumber, customerfile.customercompanynumber, locationfile.locationcompanynumber, tankfile.tankcompanynumber, and each column specified in the "Where" statement. If != and NOT IN() are bad for performance, what are the other options beside listing everything I do need? I have 355 stores and simply need to exclude two of them for reporting purposes. Would it be faster performance-wise to use a sub-select than != ?
  10. How are you initiating the XMLHTTP object? myRequest = new XMLHttpRequest(); // For Firefox myRequest = new ActiveXObject('Microsoft.XMLHTTP'); // Two quick versions for IE myRequest = new ActiveXObject('Msxml2.XMLHttp');
  11. <?php $con = mysql_connect("database host", "username", "password"); $query = "SELECT col_1, col_2, col_3 FROM table"; $result = mysql_query($query, $con); while($data = mysql_fetch_array($result)) { echo($data['col_1'].' '.$data['col_2'].' '.$data['col_3'].'<br />'); } ?> You'll have to substitute your database login information, column names, and table name of course...
  12. It's a list of variables passed using the "GET" method... Check out this wikipedia link http://en.wikipedia.org/wiki/Query_string
  13. Change your script to: $query = "SELECT sed_statistics.status, COUNT(sed_statistics.id) AS my_count FROM sed_statistics LEFT JOIN equivalences ON sed_statistics.status = equivalences.equiv GROUP BY sed_statistics.status ORDER BY sed_statistics.status ASC LIMIT 0, 30"; $result = mysql_query($query) or die(mysql_error()); // Print out the contents of each row into a table while($row = mysql_fetch_array($result)) { echo $row['status']; echo " "; echo $row['my_count']; }
  14. SELECT * FROM file_items LEFT JOIN files ON file_items.id = files.id WHERE files.type = "needed type here" ORDER BY file_items.view DESC LIMIT 0, 1
  15. Ooops... make that <select name='category'> <? $artcat = mysql_query("SELECT * FROM artcat ORDER BY id DESC",$db); while ($artcat_data = mysql_fetch_array($artcat)) { $artcat_id=$artcat_data["id"]; $artcat_title=$artcat_data["title"]; if($artcat_id == $category) { echo('<option value="'.$artcat_id.'" selected="selected">'.$artcat_title.'</option>'); } else { echo('<option value="'.$artcat_id.'">'.$artcat_title.'</option>'); } } ?> </select>
  16. Nevermind... Figured it out as soon as I posted... I forgot to clear the innerHTML on the div before I appended the data...
  17. Only a month using AJAX and less than 3 days using JSON, so this is probably a stupid mistake... Here's the client side... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>JSON Client</title> <script type="text/javascript" language="javascript"> var request = null; try { request = new XMLHttpRequest(); } catch(e) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e2) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e3) { alert("Your browser is not AJAX compatible!"); } } } function sendRequest() { var url = './json_server.php'; request.open("GET", url, true); request.onreadystatechange = doResponse; request.send(null); } function doResponse() { if(request.readyState == 4) { if(request.status == 200) { var response = eval('(' + request.responseText + ')'); for(var i = 0; i <= response.car.length - 1; i++) { document.getElementById('data_div').innerHTML += response.car[i] + '<br />'; } } else { document.getElementById('data_div').innerHTML = '<div align="center"><h3>Error Loading Data...</h3></div>'; } } else { document.getElementById('data_div').innerHTML = '<div align="center"><img src="./images/loader.gif" title="Loading..." alt="Loading..." /></div>'; } } </script> </head> <body> <div align="center"> <div id="data_div" style="height: 400px; width: 400px; background-color: #cccccc; border: 1px solid #000000; font-size: 38px; color: #000000; font-weight: bold;"> </div> <br /> <br /> <input type="button" value="Run JSON Test" onclick="sendRequest();" /> </div> </body> </html> Here's the server side... <?php header("Content-type: text/plain"); $data = '{ "car" : ["color", "red"] }'; echo($data); exit; ?> When I check the readyState it stays 3 and never returns a readyState of 4, so the loader animation never ends even though it returns the data... What am I doing wrong? It works if I don't have the "For" loop and simply return response.car[0]
  18. When you select the title, intro and article I assume that you are pulling them from a database table and I assume you have the current category stored there as well. If so, I would try something like this... (assume $category is the current category id pulled from your database) <select name='category'> <? $artcat = mysql_query("SELECT * FROM artcat ORDER BY id DESC",$db); while ($artcat_data = mysql_fetch_array($artcat)) { $artcat_id=$artcat_data["id"]; $artcat_title=$artcat_data["title"]; if($artcat_id = $category) { echo('<option value="'.$artcat_id.'" selected="selected">'.$artcat_title.'</option>'); } else { echo('<option value="'.$artcat_id.'">'.$artcat_title.'</option>'); } } ?> </select>
  19. Try this to see what errors you get... mysql_select_db("Database Name Goes Here", $con); mysql_query("INSERT INTO `emails` (`Name`, `Gender`, `Email`, `Comments`) VALUES ('$name', '$gender', '$email', '$comments')") or die(mysql_error());
  20. $query = 'SELECT column_comment AS comment FROM information_schema.columns WHERE table_schema = "Database Name Here" && table_name = "Table Name Here" && column_name = "Column Name Here"'; $result = mysql_query($query, $connection) or die(mysql_error()); $comment = mysql_fetch_array($result); echo($comment['comment']);
  21. Okay...maybe I'm making this too simple, but are you simply wanting to pull all records with with inviteID = 1, weddingid = 1, and all records with a type of P or S? If so... select wedding_guest.fname, wedding_guest.mi, wedding_guest.lname, wedding_prefix.prefix, wedding_guest.type from wedding_guest left outer join wedding_prefix on wedding_guest.prefix = wedding_prefix.id where ( wedding_guest.InviteID = 1 ) and ( weddingid = '1) and (type = 'P' OR type = 'S' );
  22. As far as the MySQL side... 'SELECT m.comp_ID AS id, m.competition AS comp, m.round AS round, m.venue AS venue, m.date AS date, m.home_ranking AS h_rank, m.away_ranking AS a_rank, m.home_team AS h_team, m.away_team AS a_team, m.result AS result, s.report AS report FROM main AS m LEFT JOIN second_table AS s ON s.comp_ID = m.comp_ID WHERE m.comp_ID = " place your search criteria here "'; Substitute the field names and table names with yours...
  23. Are you getting any PHP errors? Try this if you have a foreign key set... $sql1 = 'SELECT orders.customers_email_address, orders.date_purchased, orders.order_total, customers.customers_password FROM orders, customers WHERE orders.customers_email_address = "'.$_POST['myemail']'.'" AND orders.order_total = "100.00" AND customers.customers_password = "'.md5($_POST['password']).'"'; Otherwise join the tables on the referenced key... $sql1 = 'SELECT orders.customers_email_address, orders.date_purchased, orders.order_total, customers.customers_password FROM orders LEFT JOIN customers ON orders.customer_ID = customer.customer_ID WHERE orders.customers_email_address = "'.$_POST['myemail']'.'" AND orders.order_total = "100.00" AND customers.customers_password = "'.md5($_POST['password']).'"'; The orders.customer_ID and customer.customer_ID will need to be whatever your referenced key is. Also, is the orders.order_total = "100.00" valid? Does the customer have an order_total field with 100.00 in it? If not, that would cause the query to return without any results.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.