I wonder whether someone may be able to help me please.
I’m using the code below to create a table which lists location records for the current user.
<form name="locationsconsole" id="locationsconsole" method="post" action="locationsaction.php">
<table width="865">
<tr>
<th width="22"></th>
<th width="236"><div align="left">Location Name</div></th>
<th width="244"><div align="left">Location Address</div></th>
<th width="71"></th>
</tr>
<?php
$query = "SELECT l.*, COUNT(f.locationid) totalfinds FROM detectinglocations l LEFT JOIN finds f ON f.locationid = l.locationid WHERE l.userid = '$idnum' GROUP BY l.locationname";
$result = mysql_query($query) or die('error');
while($obj=mysql_fetch_object($result))
{
?>
<tr>
<td><input type="hidden" name="lid" value="<?php echo $obj->locationid;?>"/></td>
<td><?php echo $obj->locationname;?></td>
<td><?php echo $obj->returnedaddress;?></td>
<td><input name="type" type="submit" value="View Details"/></td>
</tr>
<?php
}
?>
</table>
</form>
You’ll see that on each row there is a button which takes the user to another page via locationsaction.php which is listed below.
<?php
session_start();
$_SESSION['lid'] = $_POST['lid'];
if (isset($_POST['type'])) {
$urls = array(
'View Details' => 'viewlocation.php'
);
$url = $urls[$_POST['type']];
header("Location: " . $url);
}
?>
There are currently 3 location records in the table which is correct, and when the button is clicked the user is taken to the correct screen.
However, the problem I’m having is that no matter which row I click the button on, the record retrieved is always related to the last location record.
I’ve been trying to sort this for quite some time now, and I’ve just not been able to find a solution, despite many page re-writes.
I just wondered whether someone could take a look at this please and let me know where I’m gong wrong.
After considerable time spent researching this on the Internet, I found the solution here. I was then able to edit this to suit my needs to the following script: