Need SIMPLE php to search field in text file database
I'm looking for a php script that will search a specific field of a text file. I volunteered to put together a website for a non-profit organization - they'd like to have a member search. I found one script (PHP Text DB V 1.0) but I don't know how to limit it to just one field of the five fields for each record. I need something so they can enter the city and it would pull all the members in the database from that city - BUT, for example, if they search for the city of Dallas, they don't need John Dallas who lives in Seattle. Any help would be *greatly* appreciated.
The PHP Text DB is simple - that is, if simple means consice scripting. I've played with it a little but can't figure out how to limit it to one field (I'm assuming that can be done). It has several files but below is the seach page:
<?php include "header.php"; ?>
<?php include "menu.php"; ?>
<BR><BR>
<table><td $tdstuff%>
<form action="search.php" method="put">
<input type="hidden" name="search" value="add">
<input type="text" name= "string" >
<input type =submit value="Search">
</form>
</td>
</table>
<?php
echo "<font face=$font color=$fcolor size =$fsize>";
?>
search results:<BR><BR>
<?php
if (!$string) {exit;}
$size=filesize("data.txt");
if (!$size =="0") {
if ($search) {
$fp = fopen("data.txt","r");
$line = 0;
while (!feof ($fp) )
{ $uname = fgets($fp,filesize("data.txt"));
$line = $line + 1;
$uname2=Chop($uname);
$res = preg_split("/####/",$uname2);
if ($res[0] || $res[1] || $res[2] || $res[3] || $res[4] ) {
$c= eregi("$string", $uname);
if ($c) {
echo "<table $tablestuff>";
echo "<td $tdstuff><font face =$font size=$fsize color=$fcolor>id<td $tdstuff><font face =$font size=$fsize color=$fcolor>$line<TR>";
echo "<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field1name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[0]<TR>";
echo "<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field2name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[1]<TR>";
echo "<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field3name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[2]<tr>";
echo "<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field4name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[3]<tr>";
echo "<td $tdstuff><font face =$font size=$fsize color=$fcolor>$Field5name<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[4]<tr>";
echo "<td $tdstuff><font face =$font size=$fsize color=$fcolor>Date<td $tdstuff><font face =$font size=$fsize color=$fcolor>$res[5]";
echo "</table><BR><br>";
}
}
}
fclose($fp);
}
}
?>
Thanks for your help.
Bruce
Comments
Why file?
You must me logged in to write a comment.