Jump to content

Help with links, PHP and MYSQL


Laine

Recommended Posts

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>";
?>

Link to comment
Share on other sites

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>";
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>" . 

Link to comment
Share on other sites

Ok, it's working now.  Just have some work to do on the profile.php.  Thanks for the help :D

 

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.