Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 135,961 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,519 people online right now. Registration is fast and FREE... Join Now!




Reading only a single line from CSV

 
Reply to this topicStart new topic

Reading only a single line from CSV

tyler3
8 May, 2008 - 08:36 AM
Post #1

New D.I.C Head
*

Joined: 8 May, 2008
Posts: 1

Ok, so please excuse how new to php I am...

I have a CSV file with about a thousand entries in it. I can pull up all of the data in that csv file using:
CODE

<?php
$row = 1;
$handle = fopen("test.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $num = count($data);
    echo "<p> $num fields in line $row: <br /></p>\n";
    $row++;
    for ($c=0; $c < $num; $c++) {
        echo $data[$c] . "<br />\n";
    }
}
fclose($handle);
?>



And that will display all of the information in that file. What I'm trying to accomplish is everytime the script is run, I want it to pull only a single item from the csv file. So the first time it's run, it'll pull line 0, the second time line 1, the third time line 2, and so on, so that only 1 line is displayed at a time, and each time it changes to the next one in order. How would I accomplish this??

What I'm trying to accomplish is a link being updated once every 20 minutes or so using a cron job, pulling the updated link from the CSV file so that my $data variable can display it on my site.

Thanks!

This post has been edited by tyler3: 8 May, 2008 - 08:45 AM
User is offlineProfile CardPM
+Quote Post

martin_bg
RE: Reading Only A Single Line From CSV
8 May, 2008 - 10:35 AM
Post #2

New D.I.C Head
*

Joined: 20 Mar, 2008
Posts: 15

If you can't use a session vriable to store the line number,try using database entry if such one is available. You could also save the data in a temp file if the operation is available.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 09:34AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month