Slice's Profile User Rating: -----

Reputation: 247 Stalwart
Group:
Active Members
Active Posts:
734 (0.3 per day)
Joined:
24-November 08
Profile Views:
21,140
Last Active:
User is offline Jun 12 2015 11:24 AM
Currently:
Offline

Previous Fields

Country:
GB
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   Slice has not set their status

Posts I've Made

  1. In Topic: Fgets EOF on Linux vs Windows

    Posted 12 Apr 2015

    Usually when running import scripts like this, I avoid the browser all-together. If you have access to the command line of the server, just run "php script.php". That way you get a realtime update where you script is up to in the process. Beats the hell out of looking at a white screen that's just loading.

    Regarding your code, as CTphpnwb said, you should remove the mysql_ functions. They are depreciated and will only cause you more trouble down the line.

    You could also make better use of fgetcsv for importing csv files. Here's a quick example (not debugged, so take it as an example only) for both PDO and fgetcsv. Using prepared statements on a loop like this should also increase the speed of the script, as well as it's security.

    Line 1 is only if you want to run it from command line.

    #!/usr/bin/php 
    <?php
    
    set_time_limit(0); // if it's a large csv file
    
    echo "running script.php..\n"; // good output tracking for script progress in terminal
    
    $file = './file.csv';
    
    $dsn = "mysql:host=localhost;dbname=test";
    
    try{
        $pdo = new PDO($dsn, 'user', 'password');
    }catch(PDOException $e){
        echo "error creating pdo object: " . $e->getMessage() . "\n";
    }
    
    /* create the prepared statement */
    $query = "INSERT INTO table (col1, col2, col3) VALUES (:col1, :col2, :col3)";
    
    $dbh = $pdo->prepare($query);
    
    if (($handle = fopen($file, 'r')) !== FALSE) {
    
        $row = 0; // i usually count rows so i can echo out how far i'm up to in the script
    
        echo "file opened and starting import..\n"; // echo out current stage in script
        
        while (($data = fgetcsv($handle, 1500, ';')) !== FALSE) {
                            
            $array = [];
            
            /* add data to 'array', to be inserted into your database - $data[0] == col A on csv
             * This is where you are "binding" the data to the placeholders in the above query. 
             */
    
            $array = [
               'col1' => $data[0],
               'col2' => $data[1],
               'col3' => $data[2]
            ];
    
    
            if(!empty($array)){
                
                try {
                    /* insert row to database */
                    $result = $dbh->execute($array);
                }catch(PDOException $e){
                    echo "row " . $row . " FAILED: " . $e->getMessage() . "\n";
                    continue;
                }
                
                echo "Successfully imported row " . $row . "\r";
                
            }
            
            // inc the row
            $row++;
        }
        fclose($handle);
        
        echo "\n \n upload complete \n"; // let us know script is finished.
    }
    
    


    Again, this is just an example code. If you are running it from terminal, the \n will produce a line break and \r will replace the current line.
  2. In Topic: Watching people code..

    Posted 9 Apr 2015

    I like learning from narrated coding videos, but I'm really picky when it comes to the narrator. If their voice is annoying, or they sound not at all interested, I get bored and just turn it off.

    Got linked to livecoding.tv earlier today, before I saw this topic, and one of the live streams was just someone coding whilst playing music. No idea what he was doing or why.
  3. In Topic: Choosing a Pretty URL

    Posted 9 Apr 2015

    Funnily enough, I actually figured out how to route to www.example.com/slice without affecting any other routes, I just need to makesure I blacklist usernames are equal to my path names.

    If someone tries setting there unique link as "subscribers" for example, www.example.com/subscribers would hit my subscribers action path and display that page before hitting the wildcard.

    View PostArtificialSoldier, on 08 April 2015 - 05:50 PM, said:

    Why? Is it necessarily any easier to remember which character versus something like "profile" or "user"?


    The idea was to keep the url as short as possbile for things where characters are limited, like twitter. Users will also be able to share specific things from there account, which will make the url even longer: www.example.com/slice/259072 would link to a specific item in my profile with that ID.

    I was stuck between this and coming up with my own link shortening system, where the user could click "share" on an item, and just get a url like www.example.com/1255, which I still might offer. But I'd still like to keep it short for those who want to just copy + paste the url.
  4. In Topic: Choosing a Pretty URL

    Posted 7 Apr 2015

    I was originally thinking the same thing, but didn't think I could route a wildcard on it's own with this named routing system.

    for example:
    Route::get('/{link}', 'ProfileController@view');
    /* next to a standard route */
    Route::get('/somepage', 'SomeController@action');
    
    


    Seems like it would cause issues with not letting the framework know I'm specifying a wildcard. I've just tried it, and it does work on it's own, but I'll have to do some more tinkering to see the affects with other controllers.

    Route::get('/@{link}', 'ProfileController@view');
    
    


    I originally went with the above just because it's 100% defined.

    I think I'll come back to this when it's not 4am. :sleep1:
  5. In Topic: Spring - Summer 2015 Fitness

    Posted 7 Apr 2015

    View PostDamage, on 06 April 2015 - 09:58 PM, said:

    5:30 A.M...who the fuck gets up to go running at that time? Dick


    I run at 5am every other day, but it's great once you get a habit. Always feel more awake and "fresh" during the day.

My Information

Member Title:
sudo pacman -S moneyz
Age:
25 years old
Birthday:
November 6, 1989
Gender:
Location:
United Kingdom
Interests:
web design and development

Contact Information

E-mail:
Click here to e-mail me

Friends

Showing 50 random friends of 7

Comments

Page 1 of 1
  1. Photo

    Slice Icon

    30 Jul 2012 - 09:45
    Do I need to collect my cash reward in person? ;)
  2. Photo

    modi123_1 Icon

    30 Jul 2012 - 09:09
    Oh.. someone got a new award!
Page 1 of 1