Everything posted by Lee_K
-
LOAD DATA LOCAL INFILE WHERE clause?
I've just noticed a problem that I think someone could help me with. Basically what I've got is: $var = "celebrity"; $line = str_replace("'", "\'", $line); $line[9] = strtolower($line[9]); if (strpos($line[9], $var)){ But I've noticed that if celebrity is the first word on a line, then it's not included. Why's that?! [EDIT]: I've just used all my wisdom and changed it to this which seems to work: $var = "celebrity"; $line = str_replace("'", "\'", $line); $line[9] = strtolower($line[9]); if (strpos($line[9], $var) !== FALSE){ I know it's working, but is that the correct way of doing it? Could someone explain why? Also, in the examples below, which would be correct? if (strpos($line[20], $var1) !== FALSE || strpos($line[20], $var2) !== FALSE){ Or this one: if (strpos($line[20], $var1) || strpos($line[20], $var2) !== FALSE){ I'm thinking it's probably the first of the two?
-
LOAD DATA LOCAL INFILE WHERE clause?
I had a feeling that might be the case, just wanted to double check!
-
LOAD DATA LOCAL INFILE WHERE clause?
1 more question! When I'm in phpMyAdmin and displaying all the rows, I've noticed that it will say something like: Showing rows 0 - 109 (110 total, Query took 0.0692 sec) But where is the 110th row? Why does it always seem to be 1 short?!
-
LOAD DATA LOCAL INFILE WHERE clause?
Thanks for all the help! It's been much appreciated! I'll definitely look into PDO at a later date. Just glad to get this working for now. Can I just ask, where did you learn this stuff? Did you study it in Uni or just pick it up yourself? What sort of qualifications are available for this kind of thing?
-
LOAD DATA LOCAL INFILE WHERE clause?
I've pretty much got this working now I think! I've done it differently though, instead of using PDO I've just used the usual MySQL connect. What's the difference here? Does it really matter? I'm also having a small problem with apostrophe's ( ' ) within the CSV file conflicting on input. Much appreciated for all the help with this though! It turned out to be a lot more complicated than I had thought, It's not something I could of done entirely on my own, not until I understand a bit more about PHP.
-
LOAD DATA LOCAL INFILE WHERE clause?
Not really! I've basically used this code to display the output in the browser, it was just to get me started: $file = fopen('CSV/newfile.csv', 'r'); while (($line = fgetcsv($file)) !== FALSE) { //$line is an array of the csv elements $var1 = "name"; $var2 = "address"; $line[20] = strtolower($line[20]); if (strpos($line[20], $var1) || strpos($line[20], $var2)) { echo '<pre>'; print_r($line[0]); echo "<br />"; print_r($line[7]); echo '<br />'; print_r($line[4]); echo '<br />'; print_r($line[14]); echo '<br />'; print_r($line[36]); echo '<br />'; print_r($line[39]); echo '</pre>'; } } fclose($file); Everything displays how I want it to in the browser. But I don't really know where to go from here to insert each line into the right columns of my database. I tried the first bit of code, using PDO but I don't understand the $connectionString part. From what I read on Google it should be like: $pdo = new PDO('mysql:host=localhost;dbname=mydbname', 'myusername', 'mypassword');
-
LOAD DATA LOCAL INFILE WHERE clause?
That helps a lot, but how would I include another variable? Something like: $var1 = "Find this"; $var2 = "Find that"; Or $var = "Find this" or "Find that" ; So that I could get a result if either of them are in the string? Also is there a way to make the variable so that it isn't case sensitive?
-
LOAD DATA LOCAL INFILE WHERE clause?
It's been a long process for a beginner but I'm definitely getting somewhere though! Can someone tell me if I can use wildcards like this? if ($line[20] == '%xyz%' I can get it to print the line if I use the exact phrase, but is there anyway I could just use part of the phrase inside of 2 of those, like '%xyz%'.
-
LOAD DATA LOCAL INFILE WHERE clause?
Wow thanks! There's plenty here to get me going in the right direction! Much appreciated guys! I'm going to check it all out properly tonight!
-
LOAD DATA LOCAL INFILE WHERE clause?
Ok so I basically turn each row of my CSV file into an array using the code above and then have to insert each requested row that into the database using PDO?
-
LOAD DATA LOCAL INFILE WHERE clause?
Could anyone give me some help with this? I've literally sat and scratched my head all day trying to work it out! I came across the following code: $csv = explode("\n", file_get_contents('test.csv')); foreach ($csv as $key => $line) { $csv[$key] = str_getcsv($line); } Which I believe turns my CSV file into an array? But then how do I go about using it to delete specific rows where their not like "xyz" and then convert it back into a CSV file for uploading to database?!
-
LOAD DATA LOCAL INFILE WHERE clause?
Is that the only way it can be done?
-
LOAD DATA LOCAL INFILE WHERE clause?
126 views and no replies tells me this can't be done then! Haha. What about using PHP to remove rows from the CSV file or extracting the rows I need and putting them into another CSV file before loading them into MySQL. Would that be possible?
-
LOAD DATA LOCAL INFILE WHERE clause?
Is this possible? I've basically got a cronjob script that inputs data from a CSV file into my database. Everything works fine except one of my CSV files has a lot of data that I don't need. I don't want to import all of it as it's just taking up resources. Is it possible to use something like this: "LOAD DATA LOCAL INFILE 'CSV/Filename.csv' INTO TABLE `TABLE 3` WHERE `colu` LIKE '%xyz%' FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\\\' IGNORE 1 LINES (name, date);" `colu` being column U in the CSV file?
-
PHP Login Cron Job
Thanks man! That's done the job perfectly! I would never of been able to get that right and was having no luck with Google either! Very much appreciated!
-
PHP Login Cron Job
I've tried the above, but still can't seem to get it working?
-
PHP Login Cron Job
Like this?: $url = "http://someurl.com/zipfile.zip"; $path = 'NewFolder/Newzipfile.zip'; $fp = fopen($path, 'wb'); $ch = curl_init($url); curl_setopt(CURLOPT_USERPWD, "XXXXX:XXXXX"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FAILONERROR, true); $data = curl_exec($ch); curl_close($ch); file_put_contents($path, $data); fclose($fp); $folder = 'NewFolder/'; // path to zip folder $zip_file = 'Newzipfile.zip'; // path to zip file
-
PHP Login Cron Job
I have a script that I use as a Cron Job which basically downloads a zip file on request and places it into a folder. This has been working fine, but now I have a URL that requires a username and password before it will allow me to download the file. My original script is: $url = "http://someurl.com/zipfile.zip"; $path = 'NewFolder/Newzipfile.zip'; $fp = fopen($path, 'wb'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FAILONERROR, true); $data = curl_exec($ch); curl_close($ch); file_put_contents($path, $data); fclose($fp); $folder = 'NewFolder/'; // path to zip folder $zip_file = 'Newzipfile.zip'; // path to zip file I've tried changing the URL to: http://username:password@someurl.com/zipfile.zip"; Which works fine through the Firefox browser, but doesn't seem to work in my CronJob script. Is there a way to login via the script? Thanks!
-
div or image between text?!
Managed to fix this by putting those 3 divs inside a parent div with margin: 0 auto; and a fixed with, aswell as overflow: visible. The 3 divs inside have a fixed with also with overflow: visible, and the left one has text-align: right, while the opposite side has text-align: left. It's worked anyways. Everything is central across all browsers.
-
div or image between text?!
You mean to set the background image of the parent div? I thought of that, but with the way that some fonts render across different browsers, it could end up looking different, and not how I intended. Ideally it would be better to centre the 3 of them as a whole. I have it set up now, using 3 divs, text on the left, image, text on the right. It looks exactly how I want it to, except not in the centre of the page because I have them set to float: left. Both text divs have a width of auto. But I would like to add an equal margin to the left side of the left div, and right side of the right div, to make them central.
-
div or image between text?!
I've got a parent div 940px across, height set to auto. Inside I've got a line of text, but inbetween that text right in the middle I want to put a div that contains a background image. I want the background image to sit evenly between the text so that it stretches out just as much above the text as it does below it. And I also want the text and the image div to sit central horizontally. What's the best way to achieve this?
-
.htaccess and PageSpeed Insights.
I honestly haven't a clue to be honest! Yeah I've been using GTMetrix and PageSpeed Insights. PageSpeed Insights gives me a mark of 89 - 91 out of a 100. GT Metrix gives me a page speed grade of 96% and a YSlow grade of 91%. There's a few things I could still change to improve it, but at the minute I'm thinking it could just be more hassle than its actually worth. For the time being anyways. I just wanted to know if everything looked ok in the htaccess file and that nothing's contradicting anything. I'm also unsure about the cache settings and how it will affect the daily price update on some of my pages if the user had viewed the page the previous day. Would I need to change the HTML settings at all for that?
-
.htaccess and PageSpeed Insights.
Hello, I've been trying to speed up my website via PageSpeed Insights. Which is now scoring 90 / 100. I've edited my .htaccess file quite a bit. Could someone look it over and tell me if there's anything that shouldn't be in there. AddDefaultCharset UTF-8 # BEGIN Compress text files <ifModule mod_deflate.c> <filesMatch "\.(css|js|x?html?|php|txt)$"> SetOutputFilter DEFLATE </filesMatch> </ifModule> # END Compress text files # BEGIN Expire headers <ifModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType image/x-icon "access plus 2592000 seconds" ExpiresByType image/jpeg "access plus 2592000 seconds" ExpiresByType image/png "access plus 2592000 seconds" ExpiresByType image/gif "access plus 2592000 seconds" ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" ExpiresByType text/css "access plus 604800 seconds" ExpiresByType text/javascript "access plus 2592000 seconds" ExpiresByType application/javascript "access plus 2592000 seconds" ExpiresByType application/x-javascript "access plus 2592000 seconds" ExpiresByType text/html "access plus 600 seconds" ExpiresByType application/xhtml+xml "access plus 600 seconds" </ifModule> # END Expire headers # BEGIN Cache-Control Headers <ifModule mod_headers.c> <filesMatch "\.(ico|jpe?g|png|gif|swf)$"> Header set Cache-Control "max-age=2592000, public" </filesMatch> <filesMatch "\.(css)$"> Header set Cache-Control "max-age=604800, public" </filesMatch> <filesMatch "\.(js)$"> Header set Cache-Control "max-age=2592000, private" </filesMatch> <filesMatch "\.(x?html?|php)$"> Header set Cache-Control "max-age=600, private, must-revalidate" </filesMatch> </ifModule> # END Cache-Control Headers # BEGIN Turn ETags Off <ifModule mod_headers.c> Header unset ETag </ifModule> FileETag None # END Turn ETags Off # BEGIN Remove Last-Modified Header <ifModule mod_headers.c> Header unset Last-Modified </ifModule> # END Remove Last-Modified Header # Add correct content-type for fonts AddType application/vnd.ms-fontobject .eot AddType font/ttf .ttf AddType font/otf .otf AddType font/x-woff .woff AddType image/svg+xml .svg # Compress compressible fonts AddOutputFilterByType DEFLATE font/ttf font/otf image/svg+xml ## EXPIRES CACHING ## <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/jpg "access 1 week" ExpiresByType image/jpeg "access 1 week" ExpiresByType image/gif "access 1 week" ExpiresByType image/png "access 1 week" ExpiresByType text/css "access 1 week" ExpiresByType text/html "access 1 week" ExpiresByType application/pdf "access 1 week" ExpiresByType text/x-javascript "access 1 week" ExpiresByType application/x-shockwave-flash "access 1 week" ExpiresByType image/x-icon "access 1 week" ExpiresByType application/vnd.ms-fontobject "access plus 1 year" ExpiresByType font/ttf "access plus 1 year" ExpiresByType font/otf "access plus 1 year" ExpiresByType font/x-woff "access plus 1 year" ExpiresByType image/svg+xml "access plus 1 year" ExpiresDefault "access 1 week" </IfModule> ## EXPIRES CACHING ## The 2 that concern me most are the 'Turn ETags Off' and the 'Remove Last-Modified Header'. Should both of those be in there together? Also another thing is I have a few pages where prices are updated daily. If a user was to visit 1 day, then come back the next. Would they see the updated prices with the way I have the cache settings? And if I'm scoring 90 / 100 on PageSpeed Insights, do I really need to worry about improving it further? Thanks!
-
Table Header background image repeating in each cell instead of spanning across the row.
For some reason that wasn't working in Safari for me! Firefox and IE were fine. I hadn't checked Chrome but usually if Safari isn't showing it properly, chances are Chrome wont be either.
-
Table Header background image repeating in each cell instead of spanning across the row.
I've managed to 'fix' it by applying the background image to the table, rather than to the thead. Probably not the correct way to do it, but it seems as though Safari doesn't let you apply a background image to the thead or tr.