DeanWhitehouse Posted April 23, 2008 Share Posted April 23, 2008 i have a user profile page, this page works by checking the users session_id and then gets this data from the database. Now how can i display this to other users, for example, so other users can view other users profiles(this is a really bad explanation). this is my current page <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; if ($_SESSION['is_valid'] == true){ $user_id = $_SESSION['user_id']; $sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name']; $email = $row['user_email']; echo "$username<br>"; $show_email = $row['show_email']; if ($show_email == 1) { echo "Username:<a href='mailto:$email'>$email</a>"; } elseif ($show_email == 0) { echo "Email:Hidden"; } } else { echo "Please login to view this page."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/102583-solved-user-profiles-how-can-i/ Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 Make a page named like profile.php and have links like profile.php?id=123. Then on the page, do: <?php if (isset($_GET['id'])) { //query and stuff with this ID } else { echo "Invalid user ID passed to page!"; } ?> Basically, substitute $_SESSION with $_GET in your code. =P Quote Link to comment https://forums.phpfreaks.com/topic/102583-solved-user-profiles-how-can-i/#findComment-525337 Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Author Share Posted April 23, 2008 so how would it no what id to get?? Quote Link to comment https://forums.phpfreaks.com/topic/102583-solved-user-profiles-how-can-i/#findComment-525340 Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 so how would it no what id to get?? It gets passed in the url, buddy. Quote Link to comment https://forums.phpfreaks.com/topic/102583-solved-user-profiles-how-can-i/#findComment-525341 Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Author Share Posted April 23, 2008 is this the right thing <?php if (isset($_GET['id'])) { $user_id = 'id'; $sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name']; $email = $row['user_email']; echo "$username<br>"; $show_email = $row['show_email']; if ($show_email == 1) { echo "Email:<a href='mailto:$email'>$email</a>"; } elseif ($show_email == 0) { echo "Email:Hidden"; } } else { echo "Invalid user ID passed to page!"; } ?> <a href="?id=1">Blade</a> Quote Link to comment https://forums.phpfreaks.com/topic/102583-solved-user-profiles-how-can-i/#findComment-525345 Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 No. <?php if (isset($_GET['id'])) { $user_id = $_GET['id']; $sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name']; $email = $row['user_email']; echo "$username<br>"; $show_email = $row['show_email']; if ($show_email == 1) { echo "Email:<a href='mailto:$email'>$email</a>"; } elseif ($show_email == 0) { echo "Email:Hidden"; } } else { echo "Invalid user ID passed to page!"; } ?> There. NOW, to access this page, it'd be: <a href="profile.php?id=1">Blade</a> Assuming that the page is named profile.php. You'd probably make these links on a userlist page and dynamically insert the ID to link to their profile. Quote Link to comment https://forums.phpfreaks.com/topic/102583-solved-user-profiles-how-can-i/#findComment-525348 Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Author Share Posted April 23, 2008 i think i might be able to "dynamically create links" but i'm not sure, do i just make an echo for each link and then it will only display them if they are in the database? Quote Link to comment https://forums.phpfreaks.com/topic/102583-solved-user-profiles-how-can-i/#findComment-525351 Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 i think i might be able to "dynamically create links" but i'm not sure, do i just make an echo for each link and then it will only display them if they are in the database? Here... <?php if (isset($_GET['id'])) { if ((int) $_GET['id'] > 0) { $user_id = $_GET['id']; $sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name']; $email = $row['user_email']; echo "$username<br>"; $show_email = $row['show_email']; if ($show_email == 1) { echo "Email:<a href='mailto:$email'>$email</a>"; } elseif ($show_email == 0) { echo "Email:Hidden"; } exit(); } else { echo "Invalid user ID passed to page! <br />"; echo "<a href=\"profile.php\">Return to user list</a>"; exit(); } } //No ID passed to page, display user list: $query = "SELECT user_id, user_name FROM $user"; $result = mysql_query($query) or die("Error:" . mysql_error()); if (mysql_num_rows($result) > 0) { echo "User List:<br />"; while ($row = mysql_fetch_assoc($result)) { echo '<a href="profile.php?id=' . $row['user_id'] . '">' . $row['user_name'] . '</a><br />'; } } ?> I hate to do it for you, but there you go. Might be syntax error somewhere, not sure, and you might want to change something at some point, so you can if you want, lol. It should work like that though. Save it as profile.php. Quote Link to comment https://forums.phpfreaks.com/topic/102583-solved-user-profiles-how-can-i/#findComment-525358 Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Author Share Posted April 23, 2008 thanks, i think i was close mine was <?php require_once 'db_connect.php'; if (isset($_GET['id'])) { $user_id = $_GET['id']; $sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name']; $email = $row['user_email']; echo "$username<br>"; $show_email = $row['show_email']; if ($show_email == 1) { echo "Email:<a href='mailto:$email'>$email</a>"; } elseif ($show_email == 0) { echo "Email:Hidden"; } } ?> Members <?php $sql1 = "SELECT * FROM $user WHERE `user_name` AND `user_id`"; $result1 = mysql_query($sql1); $row1 = mysql_fetch_assoc($result1); $username1 = $row1['user_name']; $userid = $row1['user_id']; ?> <a href="?id=<?php echo "$userid"; ?>"><?php echo "$username1"; ?></a> Quote Link to comment https://forums.phpfreaks.com/topic/102583-solved-user-profiles-how-can-i/#findComment-525361 Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 Almost, but not quite. Yours still displays the member list even if it pulls a profile. P.S: On mine, BE SURE TO INCLUDE YOUR db_connect.php script. =) Quote Link to comment https://forums.phpfreaks.com/topic/102583-solved-user-profiles-how-can-i/#findComment-525362 Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Author Share Posted April 23, 2008 have done thanks, now i will need to set a page limit, i'm assuming i can do this by done by adding a sql limit? for example LIMIT 10 Quote Link to comment https://forums.phpfreaks.com/topic/102583-solved-user-profiles-how-can-i/#findComment-525388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.