Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Lee_K

Members
  • Joined

  • Last visited

Reputation Activity

  1. Like
    Lee_K reacted to Chris Day in LOAD DATA LOCAL INFILE WHERE clause?   
    because it counts row 0 as a row
  2. Like
    Lee_K reacted to Chris Day in LOAD DATA LOCAL INFILE WHERE clause?   
    learnt most of the PHP i know at school ... not in lessons but in my free periods i had while i was in 6th form. But the job im in now have helped me develop my skills alot quicker.
  3. Like
    Lee_K reacted to Chris Day in LOAD DATA LOCAL INFILE WHERE clause?   
    You can use addslashes($var) to escape the single quotes
     
    The reason why i chose PDO over mysql_* is that mysql_* is being deprecated in later versions of PHP. One thing to check is that you have the PDO extension enabled in your php.ini file.
     
    If you have any more questions feel free to ask.
  4. Like
    Lee_K reacted to Chris Day in LOAD DATA LOCAL INFILE WHERE clause?   
    I have made a similar CSV data import/export in PHP. Inserting each line individually can be slow (but we import/export millions of records at a time.
    To combat this we done something like this.
    <?php $pdo = new PDO($connectionString, $user, $pass); $csv = explode("\n", file_get_contents('test.csv')); $data = array(); foreach ($csv as $key => $line) { if (mt_rand(1, 2) == 1) { // add your checks here $data[] = "(".implode(', ', $line).")"; if (count($data == 100)) { $pdo->query("INSERT INTO 'tableName' VALUES ".implode(", ", $data)); // At work we bind everything to prevent SQL injections but the code is abit more complex and i dont have time atm } } else { continue; } } $pdo->query("INSERT INTO 'tableName' VALUES ".implode(", ", $data)); ?>  
    What this does is inserts the data 100 records at a time this greatly improves the speed.
     
    At work i also detect for failed queries (i.e. we have unique constraints on certain tables/columns) so if a batch of 100 failed we would then try 4 batches of 25 then if that failed we would try each one individually so we dont miss any records.
  5. Like
    Lee_K reacted to Chris Day in LOAD DATA LOCAL INFILE WHERE clause?   
    The easiest way would be to use strpos() like so
     
     
    $var = "Find me"; if (strpos($line[20], $var)) { // string contains $var } else { // string dosent contain $var }
  6. Like
    Lee_K reacted to Chris Day in LOAD DATA LOCAL INFILE WHERE clause?   
    <?php

    // Make the searches all lower case
    $var = "find me";
    $var2 = "search";

    $line[20] = strtolower($line[20]); // make the line all lower case

    if (strpos($line[20], $var) || strpos($line[20], $var2)) { // || means OR. You can use && to mean AND
    // string contains $var
    } else {
    // string dosent contain $var
    }

    ?>
     
  7. Like
    Lee_K reacted to inlinedivblock in LOAD DATA LOCAL INFILE WHERE clause?   
    view this page http://php.net/manual/en/function.fgetcsv.php
     
    so for each loop it inserts into mysql, it is a bit slow this way, but for this purpose you can start in this way and then build on it.
     
    Within the loop you can add an if statement to not process certain lines which meet a criteria you have set, so "IF(condition is true)" then continue with insert, if not true ignore and continue to next row.
     
    i hope that kind of makes sense, makes sense in my head lol
  8. Like
    Lee_K reacted to Chris Day in LOAD DATA LOCAL INFILE WHERE clause?   
    Rather then storing the data into a new CSV file you can just insert the data from within the foreach loop, look into PDO.
  9. Like
    Lee_K reacted to inlinedivblock in LOAD DATA LOCAL INFILE WHERE clause?   
    if you want to ignore certain data possibly you can use http://www.electrictoolbox.com/mysql-insert-ignore/ instert ignore? or a NOT IN function i haven't really done anything like this on the mysql side. i tend to write a small function to do what I want in php and then insert into mysql.
  10. Like
    Lee_K reacted to inlinedivblock in LOAD DATA LOCAL INFILE WHERE clause?   
    yes use php or another programming language to sort out the data and the import into mysql
     
    so put data into an array and then you can sort it, and output into mysql.
  11. Like
    Lee_K reacted to Chris Day in PHP Login Cron Job   
    No problem, we use a very similar script for out reverse proxy so i only had to look at that
  12. Like
    Lee_K reacted to Chris Day in PHP Login Cron Job   
    rather then seting the username and password in the url set it like this
    curl_setopt(CURLOPT_USERPWD, "username:password");
  13. Like
    Lee_K reacted to Chris Day in PHP Login Cron Job   
    Lee_K ive noticed that i forgot to ass the $ch to the setopt function try adding that then if that dosent work have you got a example url and username/password you can send me so i can better test what is the issue as without an example or any errors im just stabbing in the dark.
     
    or you can add this to your script to show the curl error
    echo curl_error($ch);  
    Off Topic:
    Rather then post what was a pointless post why not try to help the OP if you are the 'expert' you say you are.
  14. Like
    Lee_K reacted to Chris Day in PHP Login Cron Job   
    The following worked for me, you would have to re-add your file handling, change the url and change the login credentials.
    <?php
    $ch = curl_init("http://www.somewebsite.com/");
    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);
    curl_setopt($ch, CURLOPT_USERPWD, "user:password");
    $data = curl_exec($ch);

    echo curl_error($ch);

    print_r($data);

    curl_close($ch);

    ?>Please note this was used to send the username and password for basic authentication set up on a Ubuntu system using .htpasswd and .htaccess
  15. Like
    Lee_K reacted to Chris Day in Importing & into MySQL   
    What you can do is make an identical table in a diffrent database but with no key constraints and import the data to that database and then run something like
     
    SELECT DISTINCT keyCol1, keyCol2, keyCol3 FROM testTable
     
    And see if the returned rows match 3166 or 3460
  16. Like
    Lee_K reacted to Kolix in PHP Post to database.   
    Okay, I will remove the { } then from my post. Make sure you aren't vulnerable to SQL-injections. Filter the input from GET- and POST-variables.
  17. Like
    Lee_K reacted to Kolix in PHP Post to database.   
    You have to set the closing ' for both. Correct is:
     
    $sql="INSERT INTO `Table1` (Name, Email) VALUES ('$_POST[Name]','$_POST[Email]')";
  18. Like
    Lee_K reacted to Weedy101 in .htaccess redirect and Google   
    The best way to handle that would be beyond my abilities with google. There are plenty of 'google experts' here though that I am sure will be able to give you a definitive answer to that one.
     
    I know that when I have changed the directory structure the robots.txt was the way to get rid of all those fake errors.
  19. Like
    Lee_K reacted to Weedy101 in .htaccess redirect and Google   
    If you read the small print on Webmaster tools google does not guarantee to index every page you submit. Also pages that have been previously submitted will be expected by the google bot and so if you don't want that to keep giving you reams of error messages in webmaster tools you will need to re-write your robot.txt file to exclude those now defunct links.
  20. Like
    Lee_K reacted to BlueDreamer in img alt   
    In that example the image has no sematic meaning (it's purely decoration) so there's no need for an ALT value. A better way of doing that would be to apply the image as a background image for the A tag.
     
    It's got nothing to do with SEO
  21. Like
    Lee_K reacted to BlueDreamer in img alt   
    That's correct. Essentially the FIGURE tag lets you do away with ALT and TITLE values on the image itsself, and since the image description is contained in the FIGCAPTION tag it's accessible to everyone, whether images are enabled or not.
  22. Like
    Lee_K reacted to BlueDreamer in img alt   
    Yes are you correct, if the text is the same a screen reader will effctively read it twice!
     
     
    A more sematic approach would be to use the FIGURE tag
     
     
    <figure> <img src="myimage.jpg" alt=""><!-- note no ALT value --> <figcaption>Description of the image</figcaption> </figure>
  23. Like
    Lee_K reacted to Ampersandwich in Regex help!   
    /\d+ml\/\d+\.?\d*oz/  
    This should be what you're looking for. i haven't quite got the time to explain how this one works at the moment but I'll update this post in a few hours with another rundown
  24. Like
    Lee_K reacted to Leonvv in Regex help!   
    You could try to concatenate them, so they become one string:
    <?php preg_match_all('', $row['name'] . $row['secondname'], $matches); Notice the dot between the variables.
     
    Léon
  25. Like
    Lee_K got a reaction from Ampersandwich in Regex help!   
    I messed around for ages trying to get that working, yet something as simple as adding an extra '[0]' was enough to fix it!
     
    I also managed to tweak this quite a bit and finally got what I wanted.
     
    There's something else i'm going to try but I think I can manage on my own (I hope). But if not i'll be back! :_
     
    Thanks again, much appreciated... You said at the start that your regex isn't great, but I think your better than you give yourself credit for.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.