I am creating a 'facebook' like site as a project and just cannot figure out how to make user profile pages!! so whenever someone registers a new page is created that others can view with their 'about me' and email on it ect. can anyone give me any advice on how to do this? (does not matter what language is needed to do this although if it is possible in php that would be best!)
thanks :)
Website programming help!!
Started by will998999, Nov 13 2010 01:08 PM
10 replies to this topic
#1
Posted 13 November 2010 - 01:08 PM
|
|
|
#2
Posted 13 November 2010 - 06:09 PM
Instead of creating a new user page for each register, you should utilize the dynamic approach that PHP gives you.
Say there is a profile.php, it will remain the same for each user. You point the user to the user's page by profile.php?profile=100 or profile.php?user=john. You access the name or ID through $_GET['profile'] or $_GET['user'] respectively.
To differentiate the content, you sanitize the id/username first, then query the database for information. Take this for example:
How far have you gotten?
Say there is a profile.php, it will remain the same for each user. You point the user to the user's page by profile.php?profile=100 or profile.php?user=john. You access the name or ID through $_GET['profile'] or $_GET['user'] respectively.
To differentiate the content, you sanitize the id/username first, then query the database for information. Take this for example:
$username = mysql_real_escape_string($_GET['id']);
$result = mysql_query("SELECT (name,age,othercolumns) FROM tbl_users WHERE `id` = $username");
$user = mysql_fetch_assoc($result); //we are only retrieving one ID
//database column 'name' will become $user['name']
echo 'Welcome to ' . $user['name'] . '\'s profile!<br/>';As you can see, you can use mysql_fetch_assoc() on the result and fill in their profile with the information in the database, purely based on the GET ID. There are a few other neat ways, you need to learn sessions for this of course if you want the profile to display extras, if the owner of the profile is viewing it (so they can delete comments etc).How far have you gotten?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 14 November 2010 - 02:14 AM
I know how to use sessions and how to the comments thing you added at the end :) thank you for your answer, much appreciated, I may sound stupid but could you just explain the profile.php?profile=100 or profile.php?user=john bit please :s thank you
#4
Posted 14 November 2010 - 03:55 AM
In your database each have something unique. ID and/or name. So in the URL to someone's profile page you add something like this: profile.php?profile=100 or profile.php?user=john. This will always point to the page profile.php but setting the $_GET['profile'] or $_GET['user'] to something unique for each profile page. Then by reading one of those values in the profile.php page you can make it show the info about the selected user. Just like Nullw0rm said.
For example:
You're will998999 and I'm Vswe. Nullw0rm have both of us on his friends list. The PHP code for this could look like this:
This will generate something like this HTML code for Nullw0rm(assuming you have id 78 and I have id 13):
When Nullw0rm click on either of our names he will be linked to profile.php. But it will set the $_GET['profile'] value to 13 if he opens my page and 78 if he open yours. Since this profile ID was firstly received from the database you can now use it to tell the database to show the profile of that user(see Nullw0rm's code).
For example:
You're will998999 and I'm Vswe. Nullw0rm have both of us on his friends list. The PHP code for this could look like this:
$sql = ''; //your database command
$result = mysql_query( $sql );
while($user = mysql_fetch_assoc($result)){
echo "<a href='profile.php?profile=" . $user['ID'] . "' >" . $user['Name'] . "</a><br />";
}
This will generate something like this HTML code for Nullw0rm(assuming you have id 78 and I have id 13):
<a href='profile.php?profile=13' >Vswe</a><br /><a href='profile.php?profile=78' >will998999</a><br />
When Nullw0rm click on either of our names he will be linked to profile.php. But it will set the $_GET['profile'] value to 13 if he opens my page and 78 if he open yours. Since this profile ID was firstly received from the database you can now use it to tell the database to show the profile of that user(see Nullw0rm's code).
#5
Posted 14 November 2010 - 06:22 AM
thanks for your help! 1 more thing, i was testing you code and got
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\XAMMP\xampp\htdocs\LINK code\profile.php on line 4
and suggestions? thanks :)
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\XAMMP\xampp\htdocs\LINK code\profile.php on line 4
and suggestions? thanks :)
#6
Posted 14 November 2010 - 07:19 AM
Add to the line before mysql_fetch_assoc() (it should be line 3 I guess):
if (!$result) {
die('Invalid query: ' . mysql_error());
}
#7
Posted 14 November 2010 - 01:04 PM
thanks all, everything working perfectly now, just wondering tho, how does facebook handle with all their users, surely they dont have people making links for all of them manually, how do they do it?
in other words how would i create a members list that lists all the members and automatically creates a link to profile.php?id= followed by their id, is this possible?
thanks :)
in other words how would i create a members list that lists all the members and automatically creates a link to profile.php?id= followed by their id, is this possible?
thanks :)
#8
Posted 14 November 2010 - 03:09 PM
That's the code I showed you. Just specify a good(for your purpose) database command and it will do the trick.
#9
Posted 15 November 2010 - 09:05 AM
?? i know how to list all members in my database but how do i automatically assign these names to a link to pofile.php?id= followed by the id of the name that the user clicks on? so if this was the list
john
will
andy
bob
then how do i automatically creates links to these names to something like this
<a href='profile.php?id=7>john</a>;
<a href='profile.php?id=8>will</a>;
<a href='profile.php?id=9>andy</a>;
<a href='profile.php?id=10>bob</a>;
without having to write it out manually, is this possible?
john
will
andy
bob
then how do i automatically creates links to these names to something like this
<a href='profile.php?id=7>john</a>;
<a href='profile.php?id=8>will</a>;
<a href='profile.php?id=9>andy</a>;
<a href='profile.php?id=10>bob</a>;
without having to write it out manually, is this possible?
#10
Posted 15 November 2010 - 02:08 PM
$res = mysql_query("SELECT * FROM users");
while ($row = mysql_fetch_assoc($res)) {
echo '<a href="profile.php?id=' . $row['id'] . '">' . $row['name'] . '</a><br />';
}
You already got this answer, so where is it you don't understand?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#11
Posted 16 November 2010 - 05:09 AM
there was one part i did not understand, but i have now figured out where i was going wrong :) thanks for all your help!!!


Sign In
Create Account

Back to top









