I need help with a dynamic link on my web page. This is a site where accommodation establishments register their details and upload a photo.
Here is the problem I have:
I have a page listing all users (user_list.php) where I retrieve details (acc_name, address, photo) of registered users from mysql database. I also have a dynamic link to a page (profile.php) where details of user is listed with a photo.
Everything works fine but when I click the link (first click on link) to the specific users details (profile.php) it displays fine. However, when I go back to my user list (user_list.php) and click the link of another registered user (profile.php) the profile of the previous user are redisplayed. I have reset/cleared all my browsing history but still have the same problem. Below is the code for the link to profile.php in my user_list php page.
<td class='tduser' width=15% align='center' valign='middle'><a href='profile.php?id=".$row['id']."'>".$row['acc_name']."</td>
I am querying the database correctly? Please provide me with a solution to this problem. I am missing something and cannot get around to solving it.
Below find the full code for my user_list.php.
<?php
include 'dbc.php';
include 'includes/title.inc.php';
page_protect();
$member = @$_GET['member'];
/******************** ADD ME TO SHOW USERS AVATAR ****************************/
$img_url_query = mysql_query("select avatar_url from users where id = '$_SESSION[user_id]'");
while($img_url_settings = mysql_fetch_array($img_url_query)) {
$img_url = $img_url_settings['avatar_url'];
}
/*****************************************************************************/
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/default.css" type="text/css" media="screen"/>
<title>Places To Stay In The Eastern Cape<?php if (isset($title)) {echo "—{$title}";} ?></title>
</head>
<body>
<div id="wrapper">
<div id="topinfobar">
<p><span class="strapline">Magazine Shelf Life: </span>June - August 2010: <span class="style1">3 Months</span></p>
</div>
<div id="topbanner1"></div>
<div id="topbanner2"></div>
<div id="topbanner3"></div>
<div id="topbanner4"></div>
<div id="cornerbox"></div>
<div id="starlogo"></div>
<div id="tourinfobar">
<p class="intro">Accommodation Directory to the Eastern Cape's nine tourism routes:</p>
<p>Tsitsikamma Route | Kouga Route | Sunshine Coast | Frontier Country
| Friendly N6 <br/>
Karoo Heartland | Greater Addo Route | Amatola Mountain Escape | Wildcoast/Cintsa</p>
</div>
<div id="info1"></div>
<div id="topnavbar">
<div id="topnav">
<?php include('includes/menu.inc.php'); ?>
</div>
</div>
<div id="register">
<table width="100%" border="0" cellspacing="0" cellpadding="5" class="main">
<tr>
<td 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">
<p><strong>My Account</strong></p>
<a href="myaccount.php">My Account</a><br />
<a href="register.php">Register Details </a><br />
<a href="imageupload.php">Upload Picture </a><br />
<a href="profile.php">User Profile </a><br />
<a href="mysettings.php">Update Details</a><br />
<a href="list_users.php">View Users</a><br />
<a href="logout.php">Logout </a>
</div>
<?php }
/*******************************END**************************/
?>
<p> </p>
<p> </p>
<p> </p>
<p> </p></td>
<td><?php
//check if the starting row variable was passed in the URL or not
if(!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
//we give the value of the starting row to 0 because nothing was found in URL
$startrow = 0;
//otherwise we take the value from the URL
} else {
$startrow = (int)$_GET['startrow'];
}
$result = mysql_query("SELECT * FROM users LIMIT $startrow, 10") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo
"<table class='tableuser' bgcolor='#FFDB94' cellspacing='0' cellpadding='0' border='0'>
<tr>
<td class='tduser' width='10%' align='center' valign='middle' bgcolor='#FFCC66'><p><img src=\"images/avatars/{$row['avatar_url']}\"$avatar_url\" width='100' border='1' /></p></td>
<td class='tduser' width='20%' align='center' valign='middle'><p>".$row['acc_name']."</p></td>
<td class='tduser'width='20%' align='center' valign='middle'><p>".$row['address']."</p></td>
<td class='tduser' width=15% align='center' valign='middle'><a href='profile.php?id=".$row['id']."'>".$row['acc_name']."</td>
</tr>
</table>";
}
?>
<div id="pagination">
<?php
//now this is the link
echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'"> Next >> </a>';
$prev = $startrow - 10;
//only print a Previous link if a next was clicked
if ($prev >= 0)
echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'">| << Previous</a>';
?>
</div>
</td>
<h3 class="titlehdr">List Users</h3>
<p>Here you can view all registered users.</p><br />
</tr>
</table>
</div>
<div id="infostrip">
<p>Information directory to the best accommodation establishments available in the eastern cape's nine tourism routes</p>
</div>
<!-- start of bottom navigation -->
<?php include('includes/footer_menu.inc.php'); ?>
<!-- end of bottom navigation -->
<!-- start footer -->
<?php include('includes/footer.inc.php'); ?>
<!-- end footer -->
</div>
</body>
</html>