Extremely new here and to PHP and I have exhausted my newbie resources and my brain on this one. :'(
Concept: Cron Job to INSERT 5 lines per hour (Not the whole list at once)
[*]Script to read a pipe delimited text file (about 5k Lines)
[*]Open File Get last (bottom) 5 lines of file, ignore the rest
[*]Insert those 5 lines into my database
[*]Open File, Remove last (bottom) 5 lines
I am able to do parts 1-3 but not part 4 (removing last 5 lines) Please help me!
$data = array_slice(file('data.txt'), -5);
foreach($data as $value)
{
$fields=explode("|",$value);
$num=count($fields);
for ($n=0;$n<$num;$n++)
{
$null="";
print ($n==0) ? "Importing Video...<BR>" : $null;
}
// Insert into tmpvideos table here
include("includes/config.php");
$last_id_result = @mysql_query( @"SELECT ext_id FROM tmpvideos ORDER BY ext_id+0 DESC, id DESC" );
if ( 0 < @mysql_num_rows( $last_id_result ) )
{
$last_id = @mysql_result( $last_id_result, 0, "ext_id" ) + 1;
}
else
{
$last_id = "1";
}
copy($fields[3], "thumbs/ex_".$last_id.".jpg" );
$fields[3] = "thumbs/ex_".$last_id.".jpg";
set_time_limit(0);
mysql_query("INSERT into tmpvideos (id, ext_id, title, description, duration, category, date_added, thumb, video, views, rating, votes, status)
VALUES ('','".$last_id."','$fields[0]','$fields[1]','$fields[5]','$fields[6]',NOW(),'$fields[3]','$fields[2]','','','','1')");
}
I understand the 'concept' but am unable to grasp the code! I have tried many snippets and really need help.