Jump to content

KirkLogan

Members
  • Posts

    11
  • Joined

  • Last visited

About KirkLogan

  • Birthday 05/18/1992

Contact Methods

  • Website URL
    http://www.trutechunlimited.com
  • Skype
    kirk_x_logan

Profile Information

  • Gender
    Male
  • Location
    Maryland

KirkLogan's Achievements

Newbie

Newbie (1/5)

1

Reputation

  1. Your talking about a general content management system. You need to find a nice resource to learn PHP and MySQL. I would recommend you try this: http://www.lynda.com/PHP-tutorials/php-with-mysql-essential-training/435-2.html?srchtrk=index%3a6%0alinktypeid%3a2%0aq%3aPHP%0apage%3a1%0as%3arelevance%0asa%3atrue%0aproducttypeid%3a2 This is a fantastic video series geared toward beginners and the series actually takes you through development of your first CMS. Spend 2 or 3 weeks with it and you'll be off to a great start.
  2. It may also be worth noting (and correct me if im wrong here) You can enable output buffering, at which point PHP Header functions will not be limited to Pre-Content execution. Christian is right though, it is best practice to keep your redirects prior to page content. Just thought id weigh in.
  3. Sorry to unsolve, i just have one further question. Some of my .CSV fields contain commas (name fields: Last, Frst MI) Is there a good way to keep the field from terminating when it hits that comma? Edit: I read the material on ENCLOSED BY. However the .CSV im working with does not enclose its commas in "" marks. All strings within the .CSV are enclosed in "" marks however. Edit: Sorry, was quick to post. Solved using the OPTIONALLY ENCLOSED BY parameter. Thanks again.
  4. I am importing a CSV file into a MySQL Database (about 100,000 rows of data) and it seems oddly slow. I am running on a local WAMP server and I have tried optimizing my memory limits and whatnot however it does not appear to make much of a difference. (and yes I restarted the server) I am only seeing about 1,500 rows/minute give or take and this seems oddly slow to me. I would truly appreciate it if someone could take a quick look at my code or throw me a recommendation for speeding this process up. <?php include("_include/functions.html");?> <?php include("_include/constants.html");?> <?php include("_include/connection.html");?> <?php if(isset($_FILES['file'])) { $file = $_FILES['file']['tmp_name']; $table = "job"; $handle = fopen($file, "r"); // Read first (headers) record only) $data = fgetcsv($handle, 1000, ","); $query = "DROP TABLE IF EXISTS {$table}"; $result = mysql_query($query, $connection); $query = "CREATE TABLE {$table} ("; for($i=0;$i<count($data); $i++) { $input = preg_replace('/\s+/', '_', $data[$i]); $filter1 = str_replace(",", "", $input); $filter2 = str_replace(".", "", $filter1); $filter3 = str_replace("/", "", $filter2); $filter4 = str_replace("'\'", "", $filter3); $filter5 = str_replace("-", "", $filter4); $query .= $filter5.' VARCHAR(100), '; $table_headings[$i] = $filter5; } //The line below gets rid of the comma $query = substr($query,0,strlen($query)-2); $query .= ')'; // Execute query if (mysql_query($query,$connection)) {$message = "Table {$table} created successfully";} else {$message = "Error creating table: " . mysql_error(); break;} $query = "INSERT INTO {$table} ("; for($i=0;$i<count($data); $i++) { $query .= $table_headings[$i].", "; } //The line below gets rid of the comma $query = substr($query,0,strlen($query)-2); $query .= ") VALUES ("; while(($fileop = fgetcsv($handle,1000, ",")) !== false) { $appended = ""; //Build second part of query for($i=0;$i<count($data); $i++) { $appended .= "'{$fileop[$i]}', "; } //The line below gets rid of the comma $appended = substr($appended,0,strlen($appended)-2); $appended .= ")"; $final_query = $query; $final_query .= $appended; $result = mysql_query($final_query, $connection); } fclose($handle); } ?>
  5. Prepared statements? Do you have a good reference so i can read about this?
  6. Thank you sir! That is exactly what I needed.
  7. I considered that but i run into problems as i will be using the query within a while loop to import .CSV file rows into a database.
  8. I am unsure as to the best way to do this. I am building a query using the following loop: for($i=0;$i<count($data); $i++) { $query .= "'{$fileop[$i]}', "; } My problem is, at this point in the loop, I do NOT want $fileop to output its contents (it is not even defined yet). Rather i need $fileop to display exactly as is, so that the variable name is stored in the string rather than its value at this point in time. I do however want the value of $i to output within the brackets. I suppose what im asking is, is there a way to nullify store $fileop within a string so that I can call it later (within another loop) and have it actually reference the value when the query is called? (or maybe im just ass backwards here and should take a different approach to this whole section)
×
×
  • 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.