Laine Posted January 31, 2012 Share Posted January 31, 2012 Ok basically I'm working on a members page and I want the member's username to link to their profile. I've tried a couple of different things, none of which work. It's been a long time since I've done this type of thing so I can't remember how to do it. I also only want the row names (name, timezone, server, etc) to show ONCE instead of above every member's info. Any help would be greatly appreciated. Right now when you click on the username it just takes me to the page of the member I'm currently logged in as, instead of the member I clicked on. <?php echo "<table>"; $result = mysql_query("SELECT * FROM users WHERE looking='yes'"); while($row = mysql_fetch_array($result)) { echo "<tr><td>" . "NAME" . "</td><td>" . " " . "TIMEZONE" . "</td><td>" . " ". "SERVER" . "</td><td>" . " ". "CLASS" . "</td><td>" . " ". "RACE" . "</td><td>" . " ". "AA" . "</td><td>" . " ". "LEVEL" . "</td><td>" . " ". "EPIC" . "</td><td>" . " ". "CURRENT GUILD" . "</td><td>" . " ". "WILLING TO TRANSFER SERVERS" . "</td><tr>" ."<br>"; echo "<tr><td>" . "<a href=profile.php?ID=" . $row['ID'] . ">" . $row['user_name'] . "</a>" . "</td><td>" . " " . $row['timezone'] . "</td><td>" . " " .$row['server'] . "</td><td>" . " " .$row['class'] . "</td><td>" . " " . $row['race'] . "</td><td>" . " " . $row['aa'] . "</td><td>" . " " . $row['level'] . "</td><td>" . " " . $row['epic'] . "</td><td>" . " " . $row['guild'] . "</td><td>" . " " . $row['transfer'] . "</td></tr>"; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/ Share on other sites More sharing options...
The Eagle Posted January 31, 2012 Share Posted January 31, 2012 It continues to write because it's inside of the while statement, moving it above the while statement would fix that. <?php echo "<table> <tr> <td>NAME</td> <td> TIMEZONE</td> <td> SERVER</td> <td> CLASS</td> <td> RACE</td> <td> AA</td> <td> LEVEL</td> <td> EPIC</td> <td> CURRENT GUILD</td> <td> WILLING TO TRANSFER SERVERS</td> </tr> <br /> "; $result = mysql_query("SELECT * FROM users WHERE looking='yes'"); while($row = mysql_fetch_array($result)) { echo "<tr><td>" . "<a href=profile.php?ID=" . $row['ID'] . ">" . $row['user_name'] . "</a>" . "</td><td>" . " " . $row['timezone'] . "</td><td>" . " " .$row['server'] . "</td><td>" . " " .$row['class'] . "</td><td>" . " " . $row['race'] . "</td><td>" . " " . $row['aa'] . "</td><td>" . " " . $row['level'] . "</td><td>" . " " . $row['epic'] . "</td><td>" . " " . $row['guild'] . "</td><td>" . " " . $row['transfer'] . "</td></tr>"; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1313056 Share on other sites More sharing options...
Laine Posted February 1, 2012 Author Share Posted February 1, 2012 That worked for the row names, thank you Any idea on making the link work? Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1313281 Share on other sites More sharing options...
litebearer Posted February 1, 2012 Share Posted February 1, 2012 define "making the link work?" Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1313284 Share on other sites More sharing options...
Laine Posted February 1, 2012 Author Share Posted February 1, 2012 define "making the link work?" In the while statement, where I'm trying to get the username to link to the user's profile page. Right now it just takes me back to the account I'm logged in to, no matter which user I click on. Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1313285 Share on other sites More sharing options...
litebearer Posted February 1, 2012 Share Posted February 1, 2012 look at the webpage source and see what values have been placed for ?ID= also show us the code for profile.php Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1313289 Share on other sites More sharing options...
Laine Posted February 1, 2012 Author Share Posted February 1, 2012 Ok here's my member list page <?php include 'dbc.php'; page_protect(); ?> <html> <head> <title>My Account</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <?php include('includes/header.php'); ?> <?php include('includes/navmain.php'); ?><br><br> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td colspan="3"> </td> </tr> <tr> <td width="14%" valign="top"> <?php if (isset($_SESSION['user_id'])) {?> <div class="myaccount" align="center"> <p align="center"><strong>My Account</strong></p> <a href="myaccount.php">My Account</a><br> <a href="mysettings.php">Settings</a><br> <a href="logout.php">Logout </a> </div> <?php } if (checkAdmin()) { /*******************************END**************************/ ?> <p align="center"> <a href="admin.php">Admin CP </a></p> <?php } ?> <p> </p> <p> </p> <p> </p></td> <td width="100%" valign="top" style="border: 2px solid #FFF"><p> </p> <h3 class="titlehdr">Player List</h3> <?php if (isset($_GET['msg'])) { echo "<div class=\"error\">$_GET[msg]</div>"; } ?> <?php echo "<table> <tr> <td>NAME</td> <td> TIMEZONE</td> <td> SERVER</td> <td> CLASS</td> <td> RACE</td> <td> AA</td> <td> LEVEL</td> <td> EPIC</td> <td> CURRENT GUILD</td> <td> WILLING TO TRANSFER SERVERS</td> </tr> <br /> "; $result = mysql_query("SELECT * FROM users WHERE looking='yes'"); while($row = mysql_fetch_array($result)) { echo "<tr><td>" . "<a href=profile.php?ID=" . $row['ID'] . ">" . $row['user_name'] . "</a>" . "</td><td>" . " " . $row['timezone'] . "</td><td>" . " " .$row['server'] . "</td><td>" . " " .$row['class'] . "</td><td>" . " " . $row['race'] . "</td><td>" . " " . $row['aa'] . "</td><td>" . " " . $row['level'] . "</td><td>" . " " . $row['epic'] . "</td><td>" . " " . $row['guild'] . "</td><td>" . " " . $row['transfer'] . "</td></tr>"; } echo "</table>"; ?> </td> <td width="12%" valign="top"> </td> </tr> <tr> <td colspan="3"> </td> </tr> </table> </div> <?php include('includes/footer.php'); ?> </body> </html> And here's my profile.php page <?php include 'dbc.php'; page_protect(); $member=$_GET['member']; ?> <html> <head> <title>Profile Search</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <?php include('includes/header.php'); ?> <?php include('includes/navmain.php'); ?><br><br> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td colspan="3"> </td> </tr> <tr> <td width="160" valign="top"> <? if (isset($_SESSION['user_id'])) {?> <div class="myaccount"> <p><strong>My Account</strong></p> <a href="myaccount.php">My Account</a><br> <a href="mysettings.php">Settings</a><br> <a href="logout.php">Logout </a> <p>You can add more links here for users</p></div> <? } /*******************************END**************************/ ?> <p> </p> <p> </p> <p> </p> <p> </p></td> <td width="732" valign="top"><p> </p> <h3 class="titlehdr">Profile of <? echo $member;?> </h3> <table width="80%" border="0" align="center" cellpadding="10" cellspacing="5"> <tr> <td><form name="form1" method="get" action="profile.php"> User Name: <input name="member" type="text"> <input type="submit" value="Search"> </form></td> </tr> </table> <? if (isset($_GET['msg'])) { echo "<div class=\"error\">$_GET[msg]</div>"; } ?> <p><? $query = "SELECT * FROM users WHERE user_name='$member'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); if($num == 0){ echo "No results to display, please search again."; }else{ $i=0; while($i < 1){ $full_name=mysql_result($result,$i,"full_name"); $user_name=mysql_result($result,$i,"user_name"); $user_email=mysql_result($result,$i,"user_email"); $website=mysql_result($result,$i,"website"); $date=mysql_result($result,$i,"date"); echo "<table border RULES=NONE FRAME=BOX WIDTH=\"50%\"> <tr> <td>User Name:</td><td>$user_name</td> </tr> <tr> <td width = \"50%\">Name:</td><td>$full_name</td> </tr> <tr> <td>Email Address:</td><td>$user_email</td> </tr> <tr> <td>Website:</td><td>$website</td> </tr> <tr> <td>Date Joined:</td><td>$date</td> </tr> </table><br><br>"; $i++; } } ?> </td> <td width="196" valign="top"> </td> </tr> <tr> <td colspan="3"> </td> </tr> </table> </div> <?php include('includes/footer.php'); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1313307 Share on other sites More sharing options...
litebearer Posted February 1, 2012 Share Posted February 1, 2012 this ... <a href=profile.php?ID=" . $row['ID'] . "> says the GET variable is ID whereas; this... $member=$_GET['member']; is looking for a GET of member. Make them both the same Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1313309 Share on other sites More sharing options...
Laine Posted February 1, 2012 Author Share Posted February 1, 2012 Ok did that and now it's taking me to a page where there SHOULD be a profile but isn't. There is just the search box to search for a member. The end of the url is profile.php?ID= Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1313327 Share on other sites More sharing options...
litebearer Posted February 1, 2012 Share Posted February 1, 2012 show your current code for profile.php page Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1313333 Share on other sites More sharing options...
Laine Posted February 1, 2012 Author Share Posted February 1, 2012 Ok. And btw thank you for helping <?php include 'dbc.php'; page_protect(); $ID=$_GET['ID']; ?> <html> <head> <title>Profile Search</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <?php include('includes/header.php'); ?> <?php include('includes/navmain.php'); ?><br><br> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td colspan="3"> </td> </tr> <tr> <td width="160" valign="top"> <? if (isset($_SESSION['user_id'])) {?> <div class="myaccount"> <p><strong>My Account</strong></p> <a href="myaccount.php">My Account</a><br> <a href="mysettings.php">Settings</a><br> <a href="logout.php">Logout </a> <p>You can add more links here for users</p></div> <? } ?> <p> </p> <p> </p> <p> </p> <p> </p></td> <td width="732" valign="top"><p> </p> <h3 class="titlehdr">Profile of <? echo $member;?> </h3> <table width="80%" border="0" align="center" cellpadding="10" cellspacing="5"> <tr> <td><form name="form1" method="get" action="profile.php"> User Name: <input name="member" type="text"> <input type="submit" value="Search"> </form></td> </tr> </table> <? if (isset($_GET['msg'])) { echo "<div class=\"error\">$_GET[msg]</div>"; } ?> <p><? $query = "SELECT * FROM users WHERE user_name='$member'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); if($num == 0){ echo "No results to display, please search again."; }else{ $i=0; while($i < 1){ $full_name=mysql_result($result,$i,"full_name"); $user_name=mysql_result($result,$i,"user_name"); $user_email=mysql_result($result,$i,"user_email"); $website=mysql_result($result,$i,"website"); $date=mysql_result($result,$i,"date"); echo "<table border RULES=NONE FRAME=BOX WIDTH=\"50%\"> <tr> <td>User Name:</td><td>$user_name</td> </tr> <tr> <td width = \"50%\">Name:</td><td>$full_name</td> </tr> <tr> <td>Email Address:</td><td>$user_email</td> </tr> <tr> <td>Website:</td><td>$website</td> </tr> <tr> <td>Date Joined:</td><td>$date</td> </tr> </table><br><br>"; $i++; } } ?> </td> <td width="196" valign="top"> </td> </tr> <tr> <td colspan="3"> </td> </tr> </table> </div> <?php include('includes/footer.php'); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1313337 Share on other sites More sharing options...
litebearer Posted February 1, 2012 Share Posted February 1, 2012 change this $query = "SELECT * FROM users WHERE user_name='$member'"; to this $query = "SELECT * FROM users WHERE user_name='$ID'"; ALSO look thru your code and anywhere you see $member MAKE sure that you change it to $ID Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1313366 Share on other sites More sharing options...
Laine Posted February 7, 2012 Author Share Posted February 7, 2012 I tried that and it's still not working properly. When I log in, I get redirected to the profile page of the member I am logged in as (.../user.php?id=54 for example), but when I try to view another member via the member list, the url looks like this /user.php?id= with nothing after the = sign. I've looked through the code numerous times but I have no idea what's wrong. Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1315500 Share on other sites More sharing options...
DavidAM Posted February 7, 2012 Share Posted February 7, 2012 View the source of the member list in your browser to see what the links look like. Either the ID is not getting put there, or it is being ignored. Are you sure the column name is ID (uppercase) or is it id (lowercase)? Also, you really should have quotes around the entire href value. echo "<tr><td>" . '<a href="profile.php?ID=' . $row['ID'] . '">' . $row['user_name'] . "</a>" . Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1315510 Share on other sites More sharing options...
Laine Posted February 7, 2012 Author Share Posted February 7, 2012 The link in the source code looks like this (break being the member's name) <a href=profile.php?ID=>break</a> Added the quotes, thanks Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1315520 Share on other sites More sharing options...
DavidAM Posted February 7, 2012 Share Posted February 7, 2012 <a href=profile.php?ID=>break</a> -- Look Here ---------^ The member's ID did not get output. So apparently $row['ID'] does not exist or does not have a value. Check the column name. The array index (ID) is cAsE SeNsItIvE. Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1315537 Share on other sites More sharing options...
litebearer Posted February 7, 2012 Share Posted February 7, 2012 Time to repost BOTH files for us to peruse Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1315609 Share on other sites More sharing options...
Laine Posted February 8, 2012 Author Share Posted February 8, 2012 Ok, it's working now. Just have some work to do on the profile.php. Thanks for the help This is the member list page: <?php include 'dbc.php'; page_protect(); ?> <html> <head> <title>My Account</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <?php include('includes/header.php'); ?> <?php include('includes/navmain.php'); ?><br><br> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td colspan="3"> </td> </tr> <tr> <td width="14%" valign="top"> <?php /*********************** MYACCOUNT MENU **************************** This code shows my account menu only to logged in users. Copy this code till END and place it in a new html or php where you want to show myaccount options. This is only visible to logged in users *******************************************************************/ if (isset($_SESSION['user_id'])) {?> <div class="myaccount" align="center"> <p align="center"><strong>My Account</strong></p> <a href="myaccount.php">My Account</a><br> <a href="mysettings.php">Settings</a><br> <a href="logout.php">Logout </a> </div> <?php } if (checkAdmin()) { /*******************************END**************************/ ?> <p align="center"> <a href="admin.php">Admin CP </a></p> <?php } ?> <p> </p> <p> </p> <p> </p></td> <td width="100%" valign="top" style="border: 2px solid #FFF"><p> </p> <h3 class="titlehdr">Player List</h3> <?php if (isset($_GET['msg'])) { echo "<div class=\"error\">$_GET[msg]</div>"; } ?> <?php echo "<table> <tr> <td>NAME</td> <td> TIMEZONE</td> <td> SERVER</td> <td> CLASS</td> <td> RACE</td> <td> AA</td> <td> LEVEL</td> <td> EPIC</td> <td> CURRENT GUILD</td> <td> WILLING TO TRANSFER SERVERS</td> </tr> <br /> "; $result = mysql_query("SELECT * FROM users WHERE looking='yes'"); while($row = mysql_fetch_array($result)) { echo "<tr><td>" . '<a href="profile.php?ID=' . $row['id'] . '">' . $row['user_name'] . "</a>" . "</td><td>" . " " . $row['timezone'] . "</td><td>" . " " .$row['server'] . "</td><td>" . " " .$row['class'] . "</td><td>" . " " . $row['race'] . "</td><td>" . " " . $row['aa'] . "</td><td>" . " " . $row['level'] . "</td><td>" . " " . $row['epic'] . "</td><td>" . " " . $row['guild'] . "</td><td>" . " " . $row['transfer'] . "</td></tr>"; } echo "</table>"; ?> </td> <td width="12%" valign="top"> </td> </tr> <tr> <td colspan="3"> </td> </tr> </table> </div> <?php include('includes/footer.php'); ?> </body> </html> This is the profile page: <?php include 'dbc.php'; page_protect(); $ID=$_GET['id']; ?> <html> <head> <title>Profile Search</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <?php include('includes/header.php'); ?> <?php include('includes/navmain.php'); ?><br><br> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td colspan="3"> </td> </tr> <tr> <td width="160" valign="top"> <? if (isset($_SESSION['user_id'])) {?> <div class="myaccount"> <p><strong>My Account</strong></p> <a href="myaccount.php">My Account</a><br> <a href="mysettings.php">Settings</a><br> <a href="logout.php">Logout </a> </div> <? } ?> <p> </p> <p> </p> <p> </p> <p> </p></td> <td width="732" valign="top"><p> </p> <h3 class="titlehdr">Profile of <? echo $member;?> </h3> <table width="80%" border="0" align="center" cellpadding="10" cellspacing="5"> <tr> <td><form name="form1" method="get" action="profile.php"> User Name: <input name="member" type="text"> <input type="submit" value="Search"> </form></td> </tr> </table> <? if (isset($_GET['msg'])) { echo "<div class=\"error\">$_GET[msg]</div>"; } ?> <p><? $query = "SELECT * FROM users WHERE user_name='$ID'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); if($num == 0){ echo "No results to display, please search again."; }else{ $i=0; while($i < 1){ $full_name=mysql_result($result,$i,"full_name"); $user_name=mysql_result($result,$i,"user_name"); $user_email=mysql_result($result,$i,"user_email"); $website=mysql_result($result,$i,"website"); $date=mysql_result($result,$i,"date"); echo "<table border RULES=NONE FRAME=BOX WIDTH=\"50%\"> <tr> <td>User Name:</td><td>$user_name</td> </tr> <tr> <td width = \"50%\">Name:</td><td>$full_name</td> </tr> <tr> <td>Email Address:</td><td>$user_email</td> </tr> <tr> <td>Website:</td><td>$website</td> </tr> <tr> <td>Date Joined:</td><td>$date</td> </tr> </table><br><br>"; $i++; } } ?> </td> <td width="196" valign="top"> </td> </tr> <tr> <td colspan="3"> </td> </tr> </table> </div> <?php include('includes/footer.php'); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/256130-help-with-links-php-and-mysql/#findComment-1315782 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.