pages?

kaits

Mitglied
Could someone make some examples how to insert data from sql, from many txt files from one txt to pages?
for examples, there is only one txt fail with data:
1|name|email|www
2|name|email|www
3|name|email|www

now to show only one line from txt file on php page and the second line on the second page etc?

with many txt files the same?
first txt file: 1|name|email|www
second txt file: 2|name|email|www
third txt file: 3|name|email|www

and from sql database


it would be very helpful if someone could post some examples with comments what is what
when the scripts and comments are in German than it's not a problem for me ;)

thanks!
 
there are several ways to handle this problem:
you open the text file and count the rows. therefor you might use a loop and a variable that counts the times the script runs through the loop.
Code:
$i = 0;
$fp = fopen ("textfile.txt", "r");
while ($line = fgets ($fp, 1000))
{
    $i++
    echo "line " . $i . ": " . $line;
}

to limit the output, you could add something like this:
Code:
if ($i == 2)
{
    echo "line 2: " . $line;
}
this returns just the second line of your text file. 2 is a constant expression here, but you could use another variable. or you might send the value into the script by using a form oder simply a parameter in the url.
 
I think you don't understand my question :)

I want to take the data from one txt file and show it on the page but there are links on the bottom of the page: previous page and next page
I want to put the data to pages and this from one file where data is like sda|af|adsda|af|ad, from many files where data is like:
sda|af|ad
sda|af|ad
sda|af|ad

and from SQL database

or I undsrstand nothing?
I'm n00b @ PHP :(
 
you could use the funktion file() , and you have each row of the textfile in one arrayfield. then split the "fields" of each row into another array, and you have the data you want in variables.

Tip: make a loop (while or for-next or something) and each loop is for one line in the TXT-file.

that's a possible way, if you only have one TXT-File. It is more complicated with multiple TXT-files. You have to use readdir() to get the filenames, and then you have to use the same as described for one file (I mean read the file with file() )


hope that helps


Dunsti
 
Zurück