<< back | print
.TXT based 'database'
This example is using 3 .php files with diffrent input data and takes there content from ONE/the same txt based 'database' file.
How does it works?
The txt file has a content in following format:
Sport | Group| | Time | Day | Place |
Judo | Jugend | Anfänger | 17.00-18.30 | MO | Sporthalle Kupferdreh |
Handboll | Jugend / männlich | D | 17.00-18.30 | DO | Sporthalle Kupferdreh |
Dancing | Kinder (alle Gruppen: | 5-6 Jahre | 10.00-11.00 | SA | Halle Hinsbecker Berg |
Judo | Jugend | Fortgeschrittene | 18.30-20.00 | FR | Sporthalle Kupferdreh |
The .php pages are looking for a specific string and lists the line(s) which matches the
searchingword.
Example:
The judo-contact.php is looking for the word "Judo" in the .txt file. You see that there are 2 lines with 'Judo' (see above).
The following script takes those 2 lines and shows them.
judo-contact.php:
$file = "uebzeit.txt"; // database file
$suchwort = "Judo"; // searchnig word
$fp = fopen($file,'r+');
while(!feof($fp))
{
$zeile = fgets($fp,1024);
if(strstr($zeile, $suchwort)) // looking for $suchwort and show the whole line
echo "$zeile
";
}
And now the same with
dancing-contact.php:
$file = "uebzeit.txt"; // database file
$suchwort = "Dancing"; // searchnig word
$fp = fopen($file,'r+');
while(!feof($fp))
{
$zeile = fgets($fp,1024);
if(strstr($zeile, $suchwort)) // looking for $suchwort and show the whole line
echo "$zeile
";
}
Check it out:
uebzeit.txt [Database file]
judo-kontakt.php [contact page for Judo]
handball-kontakt.php [contact page for Handboll]
tanzen-kontakt.php [contact page for Dancing]
download the example package:
txt-database.zip [4 files - 7 KB]
Note: the content of the .txt file is in German and the comments in the .php file are in German as well.