Jump to content

affordit

Members
  • Posts

    264
  • Joined

  • Last visited

Everything posted by affordit

  1. I am trying to pull results from a messages table and group the messages by a thread_id I have 3 messages with the same thread_id, but when I get the results it comes out like this; SUBJECT 1 - MESSAGE 1 SUBJECT 1 - MESSAGE 1 SUBJECT 1 - MESSAGE 1 SUBJECT 1 - MESSAGE 2 SUBJECT 1 - MESSAGE 2 SUBJECT 1 - MESSAGE 2 SUBJECT 1 - MESSAGE 3 SUBJECT 1 - MESSAGE 3 SUBJECT 1 - MESSAGE 3 SUBJECT 2 - MESSAGE 1 can someone tell me where I screwed up? Here is what I have, function getMessages($user_id){ $user_id = $_SESSION['user_id']; $query = mysql_query("SELECT * FROM `messages` WHERE `recipient_id` = $user_id or `sender_id` = $user_id"); while ($row = mysql_fetch_array($query)){ $thread_id = $row['thread_id']; $result = mysql_query("SELECT COUNT(message_id) FROM `messages` WHERE `thread_id` = $thread_id"); $count = mysql_result($result,0); $i = 0; while($i != $count){ $message_id = $row['message_id']; $subject = $row['subject']; $message = $row['message']; $sender_id = $row['sender_id']; print "<p style = 'padding-left:10px; font-weight:bold;'>$message</p>"; $i++; } print "<p style = 'padding-left:10px; font-weight:bold;'><hr></p>"; } } $m = getMessages($user_id); print $m; Thanks everyone
  2. Nevermind I got it I used this: <?php $s = '<iframe width="640" height="420" src="http://www.youtube.com/embed/_LtZGQ65RNM" frameborder="5px" allowfullscreen></iframe>'; $s = str_replace('"', '\'', $s); $s = explode('src', $s); if($s[0]!== ("<iframe width='540' height='320' ")){ str_replace($s[0], "<iframe width='540' height='320' ", $s[0]); } $s = implode("src", $s); print $s; ?> Thanks for your help!
  3. I see I got it right but how do I put the string back together?
  4. I am trying to allow youtube embed cods on my site but need to change the size if it does not fit. This is the code I am trying use, can someone tell me if there is a better way, this does not work. <?php $s = '<iframe width="640" height="420" src="http://www.youtube.com/embed/_LtZGQ65RNM" frameborder="5px" allowfullscreen></iframe>'; $s = str_replace('"', '\'', $s); $s = explode(' ', $s); print $s[1]; if($s[1]!== ("width='540'")){ str_replace($s[1], "width='540'", $s[1]); } if($s[2]!==("height='320'")){ str_replace($s[2], "height='320'", $s[2]); } print_r($s); ?>
  5. Thanks Csharp I do not have access to the ini file and did know that I could change the settings at runtime, problem solved. Thanks again
  6. the object is to get around the max upload set by php.
  7. I know that you can read a file in chunks with html 5 without uploading I was hoping that I could read the chunks and write them to a new file and reassemble them after.
  8. I have a script to split video files into chunks and and write each chunk to a separate file, and another one to reassemble the files. What I can't figure out is how to read the file 1 chunk at a time without uploading it, does anyone have any idea how this might be done, or at least point me in the right direction? // File to split $filename = ""; // Target folder. Splitted files will be stored here. Original file never gets touched. $targetfolder = 'uploads'; // File size in Mb per piece/split. // For a 200Mb file if piecesize=10 it will create twenty 10Mb files $piecesize = 10; // splitted file size in MB $buffer = 1024; $piece = 1048576*$piecesize; $current = 0; $splitnum = 1; if(!file_exists($targetfolder)) { if(mkdir($targetfolder, 0777)) { //echo "Created target folder $targetfolder".br(); } } if(!$handle = fopen($filename, "rb")) { die("Unable to open $filename for read! Make sure you edited filesplit.php correctly!".br()); } $base_filename = basename($filename); $piece_name = $targetfolder.'/'.$base_filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT); if(!$fw = fopen($piece_name,"w")) { die("Unable to open $piece_name for write. Make sure target folder is writeable.".br()); } //echo "Splitting $base_filename into $piecesize Mb files ".br()."(last piece may be smaller in size)".br(); //echo "Writing $piece_name...".br(); while (!feof($handle) and $splitnum < 999) { if($current < $piece) { if($content = fread($handle, $buffer)) { if(fwrite($fw, $content)) { $current += $buffer; } else { die("filesplit.php is unable to write to target folder. Target folder may not have write permission! Try chmod +w target_folder".br()); } } } else { fclose($fw); $current = 0; $splitnum++; $piece_name = $targetfolder.'/'.$base_filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT); //echo "Writing $piece_name...".br(); $fw = fopen($piece_name,"w"); } } fclose($fw); fclose($handle); //echo "Done! ".br(); exit; ?>
  9. I solved the problem of the update not working but still need to figure out why the update is repeating the IDs. Any ideas anyone has would be helpful
  10. When I debug the update section, here is a partial list of the result; UPDATED 1851 with LAST UPDATED 03/02/2011 UPDATED 1891 with LAST UPDATED 03/02/2011 UPDATED 1853 with LAST UPDATED 03/02/2011 UPDATED 1892 with LAST UPDATED 03/02/2011 UPDATED 1855 with LAST UPDATED 03/03/2011 UPDATED 1856 with LAST UPDATED 03/03/2011 UPDATED 1857 with LAST UPDATED 03/03/2011 UPDATED 1858 with LAST UPDATED 02/26/2011 UPDATED 1859 with LAST UPDATED 03/04/2011 UPDATED 1860 with LAST UPDATED 03/04/2011 UPDATED 1861 with LAST UPDATED 03/04/2011 UPDATED 1862 with LAST UPDATED 03/04/2011 UPDATED 1893 with LAST UPDATED 03/04/2011 UPDATED 1864 with LAST UPDATED 03/04/2011 UPDATED 1864 with LAST UPDATED 03/04/2011 UPDATED 1864 with LAST UPDATED 03/04/2011 UPDATED 1862 with LAST UPDATED 03/04/2011 I can't figure out why it would repeat the same ID??
  11. OK I have no idea why this will not update the table but here is the code I wrote. I just can't see it <?php //CONNECT TO DATABASE include("sharons_dbinfo.inc.php"); mysql_connect(localhost,$user,$password); mysql_select_db($database) or die( "Unable to select database"); //OPEN THE ZIP FILE $handle = gzopen('Newegg_com-Daily_Deals_Feed.txt.gz', 'r'); //READ THE WHOLE FILE LINE BY LINE while (!gzeof($handle)) { $buffer = gzgets($handle, 4096); $buffer = str_replace("'" , "" , $buffer); $buffer = str_replace("\"" , "" , $buffer); $data = explode(",", $buffer); //SKIP THE FIRST LINE OF COLUMN NAMES if ($data[4] == "NAME"){} else{ //PUT THIS IN TO MAKE SURE IT WAS LOOKING FOR THE RIGHT RECORD print "Looking for: ". $data['4'] . " to update with new date " . $data['3']."<br>"; $item_name = $data['4']; //QUERY THE TABLE FOR PRODUCT NAME FROM ZIP FILE $query = ("SELECT * FROM `computer_memory` WHERE `NAME` = '$item_name'"); $results = mysql_query($query) or die(mysql_error()."<br /><br />".$query); $result = mysql_fetch_array($results); $num=mysql_numrows($results); //IF THE NAME EXISTS PROCEED TO UPDATE THE RECORD WITH THE NEW INFORMATION if ($num >0) { //UPDATE TABLE WITH THE NEW INFORMATION $update = ("UPDATE `computer_memory` SET `PROGRAMNAME`= '$data[0]', `PROGRAMURL`= '$data[1]', `CATALOGNAME`= '$data[2]', `LASTUPDATED`= '$data[3]', `NAME`= '$data[4]', `KEYWORDS`= '$data[5]', `DESCRIPTION`= '$data[6]', `SKU`= '$data[7]', `MANUFACTURER`= '$data[8]', `MANUFACTURERID`= '$data[9]', `UPC`= '$data[10]', `ISBN`= '$data[11]', `CURRENCY`= '$data[12]', `SALEPRICE`= '$data[13]', `PRICE`= '$data[14]', `RETAILPRICE`= '$data[15]', `FROMPRICE`= '$data[16]', `BUYURL`= '$data[17]', `IMPRESSIONURL`= '$data[18]', `IMAGEURL`= '$data[19]', `ADVERTISERCATEGORY`= '$data[20]', `THIRDPARTYID`= '$data[21]', `THIRDPARTYCATEGORY`= '$data[22]', `AUTHOR`= '$data[23]', `ARTIST`= '$data[24]', `TITLE`= '$data[25]', `PUBLISHER`= '$data[26]', `LABEL`= '$data[27]', `FORMAT`= '$data[28]', `SPECIAL`= '$data[29]', `GIFT`= '$data[30]', `PROMOTIONALTEXT`= '$data[31]', `STARTDATE`= '$data[32]', `ENDDATE`= '$data[33]', `OFFLINE`= '$data[34]', `ONLINE`= '$data[35]', `INSTOCK`= '$data[36]', `CONDITION`= '$data[37]', `WARRANTY`= '$data[38]', `STANDARDSHIPPINGCOST`= '$data[39]' WHERE `ID`= '$id'"); mysql_query($update) or die(mysql_error()."<br /><br />".$update); //if ($update){print "UPDATED ".$result['ID'];} }else{ //IF THE NAME DID NOT EXIST INSERT A NEW RECORD INTO THE TABLE $import="INSERT into computer_memory (`ID`,`PROGRAMNAME`,`PROGRAMURL`,`CATALOGNAME`,`LASTUPDATED`,`NAME`,`KEYWORDS`,`DESCRIPTION`,`SKU`,`MANUFACTURER`,`MANUFACTURERID`,`UPC`,`ISBN`,`CURRENCY`,`SALEPRICE`,`PRICE`,`RETAILPRICE`,`FROMPRICE`,`BUYURL`,`IMPRESSIONURL`,`IMAGEURL`,`ADVERTISERCATEGORY`,`THIRDPARTYID`,`THIRDPARTYCATEGORY`,`AUTHOR`,`ARTIST`,`TITLE`,`PUBLISHER`,`LABEL`,`FORMAT`,`SPECIAL`,`GIFT`,`PROMOTIONALTEXT`,`STARTDATE`,`ENDDATE`,`OFFLINE`,`ONLINE`,`INSTOCK`,`CONDITION`,`WARRANTY`,`STANDARDSHIPPINGCOST`) values('','$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','$data[11]','$data[12]','$data[13]','$data[14]','$data[15]','$data[16]','$data[17]','$data[18]','$data[19]','$data[20]','$data[21]','$data[22]','$data[23]','$data[24]','$data[25]','$data[26]','$data[27]','$data[28]','$data[29]','$data[30]','$data[31]','$data[32]','$data[33]','$data[34]','$data[35]','$data[36]','$data[37]','$data[38]','$data[39]')"; mysql_query($import) or die(mysql_error()); } } } gzclose($handle); ?> I hope someone can see what I can't Thanks everyone
  12. Got it Thanks everyone! I don't know how to mark this as solved, sorry.
  13. I only need fields 3 and 4 they are LASTUPDATED and NAME so the database can be updated without changing the ID. Not familiar with regex, have to read up on it. Is there another function that will do the job?
  14. Are your variables in the db connect file conflicting with the user variables??
  15. This is the first line that would not print right there are 40 columns in here... Crucial Technology,http://www.crucial.com/index.asp,Crucial US Product Catalog-Data Feed, 12/06/2010,"1GB kit (512MBx2) Upgrade for a Dell OptiPlex 745 Series (Desktop, Mini-Tower, and Small Form Factor) System",MEMORY MODULE,"1GB kit (512MBx2), 240-pin DIMM, DDR2 PC2-5300, NON-ECC,",CT613060,Crucial,,,,USD,,37.99,,,http://www.kqzyfj.com/click-4349884-10273954?url=http%3A%2F%2Fwww.crucial.com%2Fstore%2Faffiliateredirect.asp%3Fmtbpoid%3DC2FFE7ABA5CA7304%26aid%3D10273954%26cid%3D777292%26subid%3D890%26PRS%3Duscj,http://www.tqlkg.com/image-4349884-10273954,http://images.crucial.com/images/resources/small/package/240-pinDIMMkit_2.gif,Memory > DDR2 PC2-5300,,,,,,,,,,,Free shipping for a limited time on qualified orders,,,,,Yes,New,Limited lifetime warranty,
  16. No still set to 4096, it only does it on lines that have commas in them tried to use str_replace but not working.
  17. That works great, but not printing the whole name in some records. This line 1GB kit (512MBx2) Upgrade for a Dell OptiPlex 745 Series (Desktop, Mini-Tower, and Small Form Factor) System Is printing this "1GB kit (512MBx2) Upgrade for a Dell OptiPlex 745 Series (Desktop Any idea why?
  18. I have a script that reads a .gz file into an array and prints the name of each record but will not work on larger files. Is there a way to read 1 line at a time? Here is the code I have so far. <?php if ($handle = opendir('.')) { print "<ol>"; while (false !== ($file = readdir($handle))) { if($file != '..' && $file!="." && $file!="start_update.php" && $file!="sharons_dbinfo.inc.php" && $file!="root.php" && $file!="read_directory.php" && $file!="read_dir.php" && $file!="new_category.php" && $file!="index.php" && $file!="file_count.php" && $file!="dir_loop2.php" && $file!="dir_loop1.php" && $file!=".htaccess" && $file!="Answer.txt" && $file!="Crucial_Technology-Crucial_US_Product_Catalog_Data_Feed.txt"){ $filename = $file; $go = filesize($filename); if($go >= 1){ $filename2 = explode("-", $filename); $filename2 = $filename2[0]; echo str_replace("_"," ",$filename2) . ' | Filesize is: ' . filesize($filename) . ' bytes<br>'; $gz = gzopen($filename, 'r'); $lines = gzfile($filename,10000); foreach ($lines as $line) { $line2 = explode(",", $line); $line2 = str_replace("," , "-" , $line2); echo "<li>".str_replace("," , "-" , $line2[4])."</li><br>"; } } } } closedir($handle); } ?> </ol>
  19. I have edited the php.ini on my server but I am uploading these datafeeds to another server that I cannot change the .ini file on. The script does not time out on mine and I have already written a script to upload the files to the db but if the file is larger than 20,000,000 bytes it times out. I would just like to know if there is a cleaner way to write the code I have.
  20. I am trying to split large csv file into manageable files to upload to database, I wrote this code and it does the job but I need to speed it up to get around the 30 second time out in php can anyone help? <?php $files = glob('*.txt'); foreach ($files as $file) { $handle1 = fopen($file, "r"); $size = filesize($file); if($size > 20000000){ $line=1; $handle2 = fopen($line.$file, "w"); while (($data = fgetcsv($handle1, 10000, ",")) !== FALSE) { $row = ($data[0]."[,]".$data[1]."[,]".$data[2]."[,]".$data[3]."[,]".$data[4]."[,]".$data[5]."[,]".$data[6]."[,]".$data[7]."[,]".$data[8]."[,]".$data[9]."[,]".$data[10]."[,]".$data[11]."[,]".$data[12]."[,]".$data[13]."[,]".$data[14]."[,]".$data[15]."[,]".$data[16]."[,]".$data[17]."[,]".$data[18]."[,]".$data[19]."[,]".$data[20]."[,]".$data[21]."[,]".$data[22]."[,]".$data[23]."[,]".$data[24]."[,]".$data[25]."[,]".$data[26]."[,]".$data[27]."[,]".$data[28]."[,]".$data[29]."[,]".$data[30]."[,]".$data[31]."[,]".$data[32]."[,]".$data[33]."[,]".$data[34]."[,]".$data[35]."[,]".$data[36]."[,]".$data[37]."[,]".$data[38]."[,]".$data[39]."[,]".$data[40]); if(strlen($row)>10) { $row = str_replace('"','',$row); $row = explode("[,]", $row); fputcsv($handle2, $row); $line++; if($line == 100000){ $handle2 = fopen($line.$file, "w"); } if ($line == 200000){ $handle2 = fopen($line.$file, "w"); } if ($line == 300000){ $handle2 = fopen($line.$file, "w"); } if ($line == 400000){ $handle2 = fopen($line.$file, "w"); } if ($line == 500000){ $handle2 = fopen($line.$file, "w"); } if ($line == 600000){ $handle2 = fopen($line.$file, "w"); } if ($line == 700000){ $handle2 = fopen($line.$file, "w"); } if($line == 800000){ $handle2 = fopen($line.$file, "w"); } if ($line == 900000){ $handle2 = fopen($line.$file, "w"); } if ($line == 1000000){ $handle2 = fopen($line.$file, "w"); } if ($line == 1100000){ $handle2 = fopen($line.$file, "w"); } if ($line == 1200000){ $handle2 = fopen($line.$file, "w"); } if ($line == 1300000){ $handle2 = fopen($line.$file, "w"); } if ($line == 1400000){ $handle2 = fopen($line.$file, "w"); } if ($line == 1500000){ $handle2 = fopen($line.$file, "w"); } if ($line == 1600000){ $handle2 = fopen($line.$file, "w"); } if ($line == 1700000){ $handle2 = fopen($line.$file, "w"); } if ($line == 1800000){ $handle2 = fopen($line.$file, "w"); } if ($line == 1900000){ $handle2 = fopen($line.$file, "w"); } if ($line == 2000000){ $handle2 = fopen($line.$file, "w"); } if ($line == 2100000){ $handle2 = fopen($line.$file, "w"); } } } } } fclose($handle1); fclose($handle2); ?> Thanks everyone
  21. That is what I needed to know thanks for the help
  22. I have written a script that reads a directory of .gz files unzips to a new directory, them deletes the .gz files, and uploads the file to the database, and deletes the text file and it needs to go through about 300+ files. But some of the files have 750,000 + records and 30 seconds is not enough time so I need to break the upload down in the middle some where, and again before it starts the next file. I think I got that all right.
  23. I want to try this in a cron setting will that have any adverse effects?
×
×
  • 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.