tdies Posted February 21, 2010 Share Posted February 21, 2010 My name is Thad and I have a BPA project that is due in little more than a week. My assignment is to create a Social Networking site from scratch with two other guys in my group. They work on all of the XHTML and CSS and I am stuck (alone) doing all of the PHP (lucky me). Obviously I don't expect this project to be anything like Facebook or Myspace with my limited experience and one month to complete the project. Anyways I ran into a little snag while trying to get user profiles implemented. I am trying to find a way that I can use URL parameters connected to one php file to display all of the user profiles. For example, instead of making a separate file or folder for each user like so: http://www.socialnetworkingsite.com/profiles/thad http://www.socialnetworkingsite.com/profiles/preston http://www.socialnetworkingsite.com/profiles/brian Query the database for the userid of the user and display the url like this: http://www.socialnetworkingsite.com/profiles?userid=1 http://www.socialnetworkingsite.com/profiles?userid=2 http://www.socialnetworkingsite.com/profiles?userid=3 I have poured through google searches trying to find a solution with no luck, what I do know is that somehow it is going to have to involve the $_GET variable if i'm not mistaken. I don't know, I hope someone understands what I need to do and can provide me with a solution. Link to comment https://forums.phpfreaks.com/topic/192835-need-help-with-url-parameters/ Share on other sites More sharing options...
sader Posted February 21, 2010 Share Posted February 21, 2010 Supose u are using MySQL database. Then simple code could look like this $user_id = intval($_GET['id']); //connect $result = mysql_query("SELECT * FROM users WHERE id=$user_id LIMIT 1"); //fetch result Link to comment https://forums.phpfreaks.com/topic/192835-need-help-with-url-parameters/#findComment-1015746 Share on other sites More sharing options...
tdies Posted February 21, 2010 Author Share Posted February 21, 2010 Well see im not using the userid to log the users in, when the user comes to the site they see a login form where they must input their email address and their password to log in. In the mysql database the userid is an integer used to link the accounts table (containing the users authentication data including their email with an SHA1 Encrypted password hash) to the profiles table (which contains user information such as name, age, favorite books, favorite movies, etc) What I need to be able to do is create a profile page for each user based upon the userid in the profiles table, then I could pull all of the data based upon that unique userid and display it on that usrs profile page. For instance when I go to your profile on this forum it takes me to this page: http://www.phpfreaks.com/forums/index.php?action=profile;u=53269 "u=53269" should be a unique id for you in the phpfreaks database, then somehow in that code it pulls all relevant data for you and displays it on your profile page. Link to comment https://forums.phpfreaks.com/topic/192835-need-help-with-url-parameters/#findComment-1015751 Share on other sites More sharing options...
tdies Posted February 22, 2010 Author Share Posted February 22, 2010 I really need help on this one Link to comment https://forums.phpfreaks.com/topic/192835-need-help-with-url-parameters/#findComment-1016171 Share on other sites More sharing options...
sader Posted February 22, 2010 Share Posted February 22, 2010 ok lets' say we have file called userlist.php //connection $result=mysql_query("SELECT id FROM `profile` ORDER BY `id`"); while($row=mysql_fetch_assoc($result)) { echo "<a href='profile.php?user=".$row['id']."' target='_blank'>".$row['name']."</a><br>"; } no we need create another file profile.php where will display user data //connection $userid = intval($_GET['user']; //this comes from url profile.php?user=NUMBER $result = "SELECT * FROM `profile` WHERE `id`=$userid LIMIT 1"; $row = mysql_fetch_assoc($result); echo "<h1>".$row['name']."</h1>"; echo "E-Mail:".$row['email']."<br />"; echo "Post count:".$row['pcount']."<br />"; echo "Hoby:".$row['hoby']."<br />"; //etc. Link to comment https://forums.phpfreaks.com/topic/192835-need-help-with-url-parameters/#findComment-1016195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.