![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
Well, I have been working on learning PHP so that I can have new users on a website, and information for scheduling sent via email. Some of the information needs to stay in a database in order to call it back such as the user's userid the password their phone number email address and real name.
so, I have been working on taking some exhisting codes off the net and modifying them as a way of learning what each thing does. I have been succesful with quite a bit of the basic PHP stuff but always get stuck when working with databasing. In the following code, I am using a Pipe (|) delimited text database with "explode" to echo the data to the screen. In it's presant state the information that is returned to the screen is is actually a list of each database entry, but what I want to do is print only one entry based on the username. Can someone help me with this... <?php
$filename ="person.data"; * *
$myFile = fopen($filename, "r");
if(! $myFile){ * * * * * *
print ("File could not be opened.");
exit;
}
$fcontents = file($filename);
while (list ($line_num, $line) = each ($fcontents)) {
*
"<p><b>Line $line_num:</b> " . str_replace("<p>", "", $line) . "<br>\n";
$values = explode("|", $line);
echo "Name: " . $values[2] . " " . $values[3] . "<br>";
echo "email: <a href=mailto:$values[4]> $values[4] </a><br>";
echo "Phone Number: " . $values[5] . "</b>";
}
* * *
fclose($myFile);
?>Thank you very much in advance Mike
__________________
Here's my latest project still in the works, and I need to get rid of this "frame" situation for real. www.prideofaustin.com |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
Hey,
you could use some system commands. This code asumes that you are running a version of linux with grep installed. anyways you could go like this:
<?PHP
function grab_user($userid)
{
$result = system("grep -i '$userid' person.data");
if ($result <> "")
{
return $result;
}
else
{
return "error";
}
}
?>Then when you want to search your data for a userid you can go like this:
<?PHP
$res = grab_user("111111");
if ($res <> "error")
{
$values = explode("|", $res);
echo "Name: " . $values[2] . " " . $values[3] . "<br>\n";
echo "Email: <a href=mailto:$values[4]> $values[4] </a><br>\n";
echo "Phone Number: " . $values[5] . "</b>\n";
}
else
{
//output some error messgae here.
}
?>Anyways, that's how i'd do it. BTW this code has not been tested so it might need some debuging. Good Luck.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#3 |
|
Programmer
|
OK,
I thought we were supposed to some how put solved on these things when we were done, but not sure how to do this. I came back to post a different question on something else and realized that I didn't let you all know that I got this problem fixed now, as I have swarn off trying pipe delims, and am working straight from a MYSQL database, so, all new territory for this beginner...lol.. Though I did use pisentio's method here with this situation and it worked fine. Thanks a ton Mike.
__________________
Here's my latest project still in the works, and I need to get rid of this "frame" situation for real. www.prideofaustin.com |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
Thanks for letting us know. You can edit your first (original post)... and add the phrase '[solved]' to your title.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|