Jump to content
MakeWebGames

cpt_jack

Members
  • Posts

    6
  • Joined

  • Last visited

    Never

cpt_jack's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Re: How do I start reading from a specific line in a text file   Oh sorry i misunderstood you, the file i get each hour comes from another server and i have no control over what is in it. which means i can't remove the old data....see my problem EDIT i think i just got what you meant, i don't know why i didn't think of it before. i copy the file to my server, delete all the old lines then just insert what is rest.......i'm such an idiot for not thinking that :-) i will try that approach and let you know what happens.
  2. Re: How do I start reading from a specific line in a text file No ideas anybody? I tried using fseek() to move the pointer through the file then use stream_get_line() but either i did it wrong or it doesn't work like i thought it did. also fseek() moves the pointer to a specific byte not a line and since each line has a different amount of bytes i don't know how to tell it where to start.
  3. Re: How do I start reading from a specific line in a text file the idea is each hour the file has X amount of new lines at the end of it and i add the lines to my DB. so it starts with a file of 10 lines, i add those, next hour it has 20 lines the first 10 being the original that i now have stored so i am now only interested in the new 10 ones. does that make sense?
  4. Hi helpful people I have been having trouble with a large text file (8mb) of almost 1 million lines. I am currently using stream_get_line() to insert each line to my DB, the file i'm working with gets updated every hour but the existing data doesn't change it just gets new lines added on the end so i thought if i could count how many lines were in my DB then start stream_get_line() from the next line in the file i could skip most of the work and just insert the new lines. Problem is i can't find anything that i can use to start that function at the beginning of a specific line. here is my code so far; p.s. i put a bit in that makes it only insert the new lines and not the old ones but it still does the stream_get_line() for every line and that is the bit that takes the time.   function read_line($file, $line_num, $delimiter="\n") { $fp = fopen($file, 'r'); $count = 0; while(!feof($fp)) { $buffer = stream_get_line($fp, 100, $delimiter); list($village_id, $timestamp, $new_owner, $old_owner) = explode(',', $buffer); if($count >= $line_num) { mysql_query("INSERT INTO conquers SET village_id='$village_id', timestamp='$timestamp', new_owner='$new_owner', old_owner='$old_owner', valid= 1 ON DUPLICATE KEY UPDATE valid= 1"); } $count++; } } $file = "http://en5.tribalwars.net/map/conquer.txt"; dbconnect(5); $result1 = mysql_query("SELECT valid FROM conquers"); $line_num = mysql_num_rows($result1); dbclose(); dbconnect(5); read_line($file, $line_num); dbclose();
  5. Re: Problem with gzfile() in php5.2 Woohoo! worked like a charm :-D thanks guys/girls
  6. Hi i'm having problems with some code that imports tribalwars data into my DB, i know this code worked on my old server (php 4) but now that i have moved to a new one using php5.2 i get errors and i have googled for an hour and not found the answer :-) this is the code; <?php include '../config/config.php'; $lines = gzfile('http://en33.tribalwars.net/map/village.txt.gz', 'r'); if(!is_array($lines)) die("File could not be opened"); echo "</br>Clearing village database</br>"; mysql_query("truncate w1_villages"); foreach($lines as $line) { list($id, $name, $x, $y, $player, $points, $rank) = explode(',', $line); $name = urldecode($name); $name = addslashes($name); $y2=$y-($y%100); $x2=$x-($x%100); $continent=$y2/10+$x2/100; mysql_query("INSERT INTO w1_villages SET id='$id', name='$name', x='$x', y='$y', player='$player', points='$points', rank='$rank', continent='$continent'"); } ?> and the error is; Warning: gzfile() expects parameter 2 to be long, string given in /home/a9315141/public_html/crons/w1_village.php on line 5 File could not be opened   please help before i start to cry and pull more of my hair out.
×
×
  • Create New...