Jump to content

Profiles?


Accurax

Recommended Posts

Ive been reading around and i cant seem to find anything that mentions how to actually do this, so if someone could point me in the direction of some referance material id be very gratefull. This is where I am, and what im looking for ;

I have created a membership system, in which members can login, and create a profile for themselves, with photo's etc, howwever, a profile is not much use unless other people can view it.

Basically, im trying to find out how i can go about listing all the profiles on my sirte, and allowing other users to browse through them.

Like i said, i cant seem to find a referance on doing this, so any links and or pointers are much appreciated.

Thanks guys
Link to comment
Share on other sites

You can do this easily with some mysql queries.

[code]
<?php
$id = $_GET['id'];

if(isset($id)){
$sql = "SELECT * FROM `users` WHERE id =$id";
$res = mysql_query($sql) or die(mysql_error());
$num = mysql_numrows($res);
$row = mysql_fetch_assoc($res);

if($num > 0){
echo "Welcome to $row['username']'s profile!<br><br>\n";
echo "Name: $row['name']<br>\n";
echo "Email: $row['email']<br>\n";
echo "Picture: <img src='".$row['image']."'><br>\n";
//and whatever is in your database
}else {
echo "That user does not exist!\n";
}

}else {
echo "You have no user id specified!";
}
?>
[/code]
Link to comment
Share on other sites

And for showing a members list you can do:

[code]
<?php
$sql = "SELECT * FROM `users`";
$res = mysql_query($sql) or die(mysql_error());
$num = mysql_numrows($res);

if($num == 0){
echo "no users";
}else {
while($row = mysql_fetch_assoc($res)){
echo "<a href=profile.php?id=$row['id']>$row['username']</a>\n";
}
mysql_free_result($res);
}
?>
[/code]
Link to comment
Share on other sites

Thats what i started thinking . allthough i wasnt sure how to acheive it, my idea is to display all of the pictures of the members and let the user select which profile to see from the thumbnails ... I cant get my head around how to pass the variables so that my script knows which profile they selected.

Then i started thinking that i needed to dynamically create pages for each user....... as this would allow them to give the link to their friends so they could go straight to their profile.... which is an idea that i like.

this will eventually be a list generated by some search queries performed by the user, so the thumbnails will be dynamically created aswell.

I think once i figure out the basics of identifying which profile was selected ill be half way there tbh
Link to comment
Share on other sites

Any chance someone knows where i can find out how this works........ I dont want to simply copy and paste code, allthoguh i appreciate examples that are given..... i really need to understand this...... How does a php script know which profile it is meant to display?
Link to comment
Share on other sites

ok

url is  http://yoursite.com/show-users.php?userid=55  - so someone visits this link..

you can use GET to grab the userid var from the above url

$userid = $_GET['userid'];

the the sql statement then selects the info from the userid

$sql = "SELECT * FROM `users` WHERE id =$userid";        see the WHERE id =$userid";  part?

sorted, this is how it lists info from that specific user. taking into account that your table has a unique id for each user, else it will bugger up if 2 people have the same id etc.
Link to comment
Share on other sites

Okay here goes!
Table Example
Table name - users
table fields - user_id, username, thumbnail_link blah, blah, blah.


$sql_user_query = "SELECT * FROM users";
$sql_user_result = mysql_query($sql_user_query);

Then you start to images out the profiles using a while loop and details using a while loop.
<?php
whille($user_array= mysql_fetch_array($sql_user_result)){
?>

<tr>
<td>[color=green](a href="view_profile.php?userid[/color]<?php echo $user_array['user_id'];?>[color=green]")<img src="images/[/color]<?php echo $user_array['thumbnail_link'];?>[color=green]" width="100" height="100">(/a)[/color]
</td>
</tr>

I have had to change the link tag to avoid the BB parser in this software so (a) (/a) should obviousl be the usual html link tags

Here the php is echoing at the row for each array it finds in the database - The <a href="view_profile.php?=***dynamically sets the URL to be "view_profile.php?=(whatever the userid is in the array)

Now when they click the image it will link to view_profile.php and the query string will be after. (view_profile.php?userid=1) for example

now collect the variable in the code for view_profile.php using the following

$userid = $_GET['userid'] This collects the userid from the query string in the URL.

Hope that helps. Tried to explain best I can.

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.