Jump to content

Creating php users page


Rajada

Recommended Posts

So, I'm designing a website (who isn't?) and I created the basic framework for a users page from a tutorial I found. Using some previous knowledge I managed to make it display a few custom fields that are defined by the user. Everything works fine as is, but now I want to do a few things to it that I have not the slightest clue how to even begin...

 

Here is my user page code so far... and oh yes I'm using WordPress which is why I made it check manually for page status in my Page.php file.

 

<?php
if ( is_page('Users'))
{

echo "<ul id=\"UsersList\">";

/*
First we set how we'll want to sort the user list. You could sort them by:
------------------------
* ID - User ID number.
* user_login - User Login name.
* user_nicename - User Nice name ( nice version of login name ).
* user_email - User Email Address.
* user_url - User Website URL.
* user_registered - User Registration date.
*/
$szSort = "user_nicename";
/*
Now we build the custom query to get the ID of the users.
*/
$aUsersID = $wpdb->get_col( $wpdb->prepare("SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC", $szSort ));
/*
Once we have the IDs we loop through them with a Foreach statement.
*/

foreach ( $aUsersID as $iUserID ) :

/*
We use get_userdata() function with each ID.
*/

$user = get_userdata( $iUserID );


/*
Here we finally print the details wanted.
Check the description of the database tables linked above to see
all the fields you can retrieve.

To echo a property simply call it with $user->name_of_the_column.
*/

if($user->user_login != "Unknown") // don't show the placeholder for [unknown] author

{
echo '<a href="">' . get_avatar( $iUserID, $size = '45', $border='0') . '</a>';
echo '<li>' . ucwords( strtolower(  $user->user_login ) ) . '</li>';

if($user->favorite_player != "")
{
echo '<li>' . $user->favorite_player . '</li>';
}
if($user->player_name != "")
{
echo '<li>' . $user->player_name . '</li>';
}
}
/*
     The strtolower and ucwords part is to be sure
     the full names will all be capitalized.
*/

endforeach; // end the users loop.

echo "</ul>";
};
?>

 

 

Problem one: This does NOT sort my name, despite the tutorial's insistence that it will. I have not even a guess as to why this is.

 

Problem two: I would like to either sort this list into two columns or paginate it or both but I am not sure how to do either.

 

Problem three: I want to insert some static text between the echo '<li>'  and the  . $user->player_name . '</li>'; so that it reads:

 

o Player Name: USER'S VARIABLE ' PLAYER NAME' HERE

 

Yes that 'o' is supposed to be the list item dot. I know how strings work, I just can't get my attempts to work out syntax-wise.

 

Any help would be greatly appreciated! Tutorials, answers, suggestions, examples, anything. The extent of my previous coding knowledge is several years of UnrealScript, so you can see why this simple thing is baffling me. Frankly I'm surprised this much of it works. :P

Link to comment
Share on other sites

Try changing

$szSort = "user_nicename";

to

$szSort=user_nicename;

This is just a guess as I don't know enough about the rest of the code.  All I'm doing is using a constant here (assuming it exists, you'll know)

 

Use this to shower 'player name:'

<?php
echo '<li>Player Name: ' . $user->player_name . '</li>';

Link to comment
Share on other sites

Try changing

$szSort = "user_nicename";

to

$szSort=user_nicename;

This is just a guess as I don't know enough about the rest of the code.  All I'm doing is using a constant here (assuming it exists, you'll know)

 

I tried that, its not giving an error but it isn't sorting, it refuses to sort by anything on the commented list. It APPEARS to be sorting by default based on join date.

 

And yeah I figured out the string syntax already, but thanks, still took me forever to find it. :P

 

Oh and forget the two columns thing, I'd rather paginate it so any tuts or suggestions on that would be helpful.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.