firecat318 Posted April 25, 2008 Share Posted April 25, 2008 On my site, each user is allowed to make a small profile to describe themselves a little bit. Basically, I want to assign them a unique URL so that everybody that wants to can visit their profile. Link to comment https://forums.phpfreaks.com/topic/102822-giving-each-profile-its-own-url/ Share on other sites More sharing options...
pocobueno1388 Posted April 25, 2008 Share Posted April 25, 2008 You need to use a unique identifier in the URL for that user, such as their username or user ID. Then if the URL looks something like this: www.domain.com/profile.php?user=bob Then you can do a query to the database getting the information you need by using their username, which in this case would be "bob". Let me know if you need further explanation. Link to comment https://forums.phpfreaks.com/topic/102822-giving-each-profile-its-own-url/#findComment-526717 Share on other sites More sharing options...
firecat318 Posted April 25, 2008 Author Share Posted April 25, 2008 Alright, I can handle getting the username out of the database, but when I have it, how would I get it into the URL? Link to comment https://forums.phpfreaks.com/topic/102822-giving-each-profile-its-own-url/#findComment-526777 Share on other sites More sharing options...
pocobueno1388 Posted April 25, 2008 Share Posted April 25, 2008 Okay, here is an example. <?php $query = mysql_query("SELECT username FROM table"); $row = mysql_fetch_assoc($query); //put username into link to profile page echo "<a href='profile.php?user={$row['username']}'>Go to {$row['username']}'s Profile</a>"; ?> Now, on the profile page, the code should look like this: <?php //get username from the URL $username = mysql_real_escape_string($_GET['user']); //Get information about that user from database to display profile information $query = "SELECT * FROM users WHERE username='$username'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); //Now you can start displaying their profile information with the info from the database. echo "This is {$row['username']}'s Profile page"; ?> Link to comment https://forums.phpfreaks.com/topic/102822-giving-each-profile-its-own-url/#findComment-526780 Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 No, use $_GET. And be sure to loop through the mysql results. But yeah, use GET not POST. Link to comment https://forums.phpfreaks.com/topic/102822-giving-each-profile-its-own-url/#findComment-526781 Share on other sites More sharing options...
pocobueno1388 Posted April 25, 2008 Share Posted April 25, 2008 No, use $_GET. And be sure to loop through the mysql results. But yeah, use GET not POST. If your talking about my code, I did use $_GET. Also, why loop through the MySQL result when your only expecting one result set? Link to comment https://forums.phpfreaks.com/topic/102822-giving-each-profile-its-own-url/#findComment-526782 Share on other sites More sharing options...
firecat318 Posted April 25, 2008 Author Share Posted April 25, 2008 Okay, here is an example. <?php $query = mysql_query("SELECT username FROM table"); $row = mysql_fetch_assoc($query); //put username into link to profile page echo "<a href='profile.php?user={$row['username']}'>Go to {$row['username']}'s Profile</a>"; ?> Now, on the profile page, the code should look like this: <?php //get username from the URL $username = mysql_real_escape_string($_GET['user']); //Get information about that user from database to display profile information $query = "SELECT * FROM users WHERE username='$username'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); //Now you can start displaying their profile information with the info from the database. echo "This is {$row['username']}'s Profile page"; ?> Thanks! That is exactly what I was looking for. Link to comment https://forums.phpfreaks.com/topic/102822-giving-each-profile-its-own-url/#findComment-526790 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.