Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php loop to print usernames

Status
Not open for further replies.

moirakris

Technical User
Oct 11, 2002
82
Ok this is my first time working/modifying php code so I am a total newbie. I am trying to display the username, email, location and join date for all users stored in the users.php

It does this but it lists the first entry (admin) twice and I cannot for the life of me figure out why it's doing this.
Also is there a way to make the displayed email user address a mailto link?

Here is the code I have there now. If you need to see a live copy of it just let me know.

Thanks for any help you can give.
Warmest Regards,
Moira

Code:
<?php
// Get all users from file
 $file = file(&quot;users.php&quot;);
			
// Get amount of lines in file
$totalLines = sizeof($file);
			
// Loop through and display all users
for($line = 0; $line < $totalLines; $line++){
// Dont print out lines beginning with a comment
if(&quot;//&quot; != substr($file[$line], 0, 2)){
// Put contents of line into variables
@list($username, $password, $perm, $email, $url, $dob, $location, $joined) = explode(&quot;<del>&quot;, $file[$line]);
						
$string .= &quot;<span style = 'color: #191970;'>Name:</span> &quot;. $username.&quot;<br>&quot;;
//$string .= &quot;password (md5()): &quot;. $password. &quot;<br>&quot;;
//$string .= &quot;permission: &quot;. $perm. &quot;<br>&quot;;
$string .= &quot;<span style = 'color: #191970;'>Email:</span> &quot;. $email. &quot;<br>&quot;;
//$string .= &quot;url: &quot;. $url. &quot;<br>&quot;;
//$string .= &quot;date of birth: &quot;. $dob. &quot;<br>&quot;;
$string .= &quot;<span style = 'color: #191970;'>Location:</span> &quot;. $location. &quot;<br>&quot;;
$string .= &quot;<span style = 'color: #191970;'>Joined:</span> &quot;. $joined. &quot;<br><hr>&quot;;
echo $string;
								}
}
?>
 
Woo ok i got it to remove the extra admin, no it wasn't in the database twice, not really sure what I did but it worked lol. I also got the username to be a mailto link

Now I just need to figure out how to have it output the users.php sorted in alphabetical order on the output. It is stored in the users.php by order of entry.

Any ideas? Here is the revised code

Code:
<?php
// Get all users from file
$file = file(&quot;users.php&quot;);
			
// Get amount of lines in file
$totalLines = sizeof($file);
			
// Loop through and display all users
for($line = 0; $line < $totalLines; $line++){
// Dont print out lines beginning with a comment
if(&quot;//&quot; != substr($file[$line], 0, 2)){
// Put contents of line into variables
@list($username, $password, $perm, $email, $url, $dob, $location, $joined) = explode(&quot;<del>&quot;, $file[$line]);
				
$string = &quot;<hr><a href = 'mailto:$email'>&quot;.ucfirst($username). &quot;</a>&quot;.$modified.&quot;<br>&quot;;
//$string .= &quot;password (md5()): &quot;. $password. &quot;<br>&quot;;
//$string .= &quot;permission: &quot;. $perm. &quot;<br>&quot;;
//$string .= &quot;Email: &quot;. $email. &quot;<br>&quot;;
//$string .= &quot;url: &quot;. $url. &quot;<br>&quot;;
//$string .= &quot;date of birth: &quot;. $dob. &quot;<br>&quot;;
$string .= &quot;<span style = 'font-size: smaller;'>Location: &quot;. $location. &quot;</span><br>&quot;;
//$string .= &quot;Joined: &quot;. $joined. &quot;<br><hr>&quot;;
echo $string;
	}
    }
?>

And here is what the entries in the users.php show as if you need to know
Code:
moirakris<del>*****<del>2<del>email@isp.net<del><del><del>City, State<del>01.21.2004 
kelly<del>******<del>0<del>email@isp.com<del><del><del>City, State<del>01.25.2004

Once again any help would be greatly appreciated!
Thanks!!!
Moira

Moira
&quot;Those that stop learning, stop living.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top