Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 1st, 2004, 7:05 PM   #1
scorpiosage
Programmer
 
scorpiosage's Avatar
 
Join Date: Aug 2004
Location: Austin, Tx
Posts: 55
Rep Power: 5 scorpiosage is on a distinguished road
Send a message via AIM to scorpiosage Send a message via Yahoo to scorpiosage
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 &quot;frame&quot; situation for real. www.prideofaustin.com
scorpiosage is offline   Reply With Quote
Old Sep 2nd, 2004, 10:12 AM   #2
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Old Oct 9th, 2004, 6:35 AM   #3
scorpiosage
Programmer
 
scorpiosage's Avatar
 
Join Date: Aug 2004
Location: Austin, Tx
Posts: 55
Rep Power: 5 scorpiosage is on a distinguished road
Send a message via AIM to scorpiosage Send a message via Yahoo to scorpiosage
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 &quot;frame&quot; situation for real. www.prideofaustin.com
scorpiosage is offline   Reply With Quote
Old Oct 9th, 2004, 11:26 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC