graham23s Posted May 2, 2007 Share Posted May 2, 2007 Hi There Guys, I have just made a very very basic forum everything is working great apart from 1 tiny thing, i was wanting the posters(username) to be clickable so it takes you to thier profile, the way it is at the moment whoever is logged in, when they click on a username it takes you to thier profile regardless on who you click on, heres my coding: <?php // For register_global on PHP settings////////////////////////////////////////////// $member = $_COOKIE['member']; session_start(); // you must put this to read session variables///////////////////// if (empty($member) || !isset($member)) // fail to read the browser cookie/////////// { // Try to read session if (empty($_SESSION['member']) || !isset($_SESSION['member'])) { header("Location: login.php"); // redirect user to login////////////////////// exit; } else { $member = $_SESSION['member']; } } //Includes... ////////////////////////////////////////////////////////////////////// include("includes/db_connection.php"); include("includes/constants.php"); include("includes/header.php"); include("includes/loginnav.php"); // Query the database to get the usersname.../////////////////////////////////////// $sql = "SELECT * FROM membership"; $result = mysql_query($sql); $row = mysql_fetch_array($result); extract($row); $m_id = $row['id']; ?> <?php // Get the id from the previous post...///////////////////////////////////////////// $id = $_GET['id']; // Query the database for the posts...////////////////////////////////////////////// $sql = "SELECT * FROM forum_posts WHERE id='$id'"; $result = mysql_query($sql) or die (mysql_error()); $rows = mysql_fetch_array($result); ?> <br /> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF"> <tr> <td bgcolor="#F8F7F1"><p>Post Title-><font color="red"><? echo $rows['topic']; ?></p></font><hr /></td> </tr> <tr> <td bgcolor="#F8F7F1"><p><? echo $rows['message']; ?><hr /></td> </tr> <tr> <td bgcolor="#F8F7F1"><p><i>Posted By:</i> <a href="profile.php?id=<?php echo $m_id; ?>"><? echo $rows['poster_id']; ?></a><i> On: </i><? echo $rows['datetime']; ?></td> </tr> </table></td> </tr> </table> <br /><hr /> <?php // Query the second forum table...////////////////////////////////////////////////// $sql2 = "SELECT * FROM forum_replies WHERE main_id='$id'"; $result2 = mysql_query($sql2); while($rows = mysql_fetch_array($result2)) { ?> <br /> <table width="80%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td width="10%" bgcolor="#F8F7F1"><p>Reply</td> <td width="60%" bgcolor="#F8F7F1"><p><?php echo $rows['reply_message']; ?></td> </tr> <tr> <td bgcolor="#F8F7F1"><p>Poster</td> <td bgcolor="#F8F7F1"><a href="profile.php?id=<?php echo $m_id; ?>"><?php echo $rows['reply_id']; ?></a></td> </tr> </table> <?php } $sql3="SELECT view FROM forum_posts WHERE id='$id'"; $result3=mysql_query($sql3); $rows = mysql_fetch_array($result3); $view = $rows['view']; // if have no counter value set counter = 1 if(empty($view)) { $view=1; $sql4="INSERT INTO forum_posts(view) VALUES ('$view') WHERE id='$id'"; $result4=mysql_query($sql4); } // count more value $addview = $view+1; $sql5="update forum_posts set view='$addview' WHERE id='$id'"; $result5=mysql_query($sql5); mysql_close(); ?> <br /><hr /> <table width="50%" border="0" cellpadding="3" cellspacing="1"> <form name="form1" method="post" action="add_reply.php"> <tr> <td bgcolor="#E2E2E2" width="14%"><p>From</td> <td bgcolor="#E2E2E2"width="84%"><input name="reply_id" type="text" id="name" size="46" value="<?php echo $username; ?>" disabled></td> </tr> <tr> <td bgcolor="#E2E2E2" valign="top"><p>Reply</td> <td bgcolor="#E2E2E2"><textarea name="reply_message" cols="35" rows="5" id="reply_message"></textarea></td> </tr> <tr> <td bgcolor="#E2E2E2"> </td> <input name="id" type="hidden" value="<?php echo $id; ?>"></td> <td bgcolor="#E2E2E2"> <input type="submit" name="submit" value="Add Reply"><input type="reset" name="submit" value="Reset"> </td> </tr> </table> <?php // Include the footer... include("includes/footer.php") ?> i tried to make $m_id the link to the profiles but no luck, what would be the best way to do this? thanks for your help guys Graham Link to comment https://forums.phpfreaks.com/topic/49639-hyperlinking-usersname-to-profile-id/ Share on other sites More sharing options...
Fearpig Posted May 2, 2007 Share Posted May 2, 2007 Sorry, I didn't read through the code but.... You'd want somethng like this: <?php echo "<a href='UserProfiles.php?id=$UserID'>$UserName</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/49639-hyperlinking-usersname-to-profile-id/#findComment-243383 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.