Page 1 of 1

link to more info from queried list

Posted: Mon Jun 20, 2005 10:32 pm
by rfigley
I have a page which I list people from a directory using a search which gives a result like:

Name Address Phone Details
Name1 address1 phone1 detail_link
name2 address2 phone2 detail_link
etc

Of course each of these records has an ID but also a lot of additional information. I want the "detail_link" to use the ID of the selected link (record) to retrieve that information. Not sure how the code should go to do that.

Posted: Tue Jun 21, 2005 1:04 am
by timvw
So you make a detail.php page that accepts the id...

Code: Select all

<?php
if (issset($_GET['id']))
{
  // lookup record with that id
}
else
{
  // users needs to select a record first, display list
  header('Location: http://mysite.example.com/list.php');
}
?>
Offcourse your list would generate html like

Code: Select all

&lt;a href=&quote;detail.php?id=xxxx&quote;&gt;item xxxx&lt;/a&gt;
&lt;a href=&quote;detail.php?id=yyyy&quote;&gt;item yyyy&lt;/a&gt;

Posted: Tue Jun 21, 2005 1:35 am
by Jim_Bo
Hi,

Do you mean show basic details on one page, then link to full details on another?

Try:

index.php

Code: Select all

<?php 

// connection details

$sql = "SELECT * FROM table ";

$result = mysql_query($sql); 
while ($row = mysql_fetch_array($result)) {
	$id = $row['id'];
	$name = $row['name'];
	$bla = $row['bla'];

         echo "$name - $bla <a  href=\"../full_details.php?id=$id\">(view full details)</a>";

}

?>
full_details.php

Code: Select all

<?php

// connection details

$id = $_GET['id'];

$sql = "SELECT * FROM table WHERE id = '$id'";

$result = mysql_query($sql); 
while ($row = mysql_fetch_array($result)) {
	$id = $row['id'];
// call on other table rows you want to display

         echo "$name - $bla etc etc";
		 
}

?>
Thats just a basic concept to give you the idea.

I like to break out of the php tags and use

Code: Select all

<td><div align="left"><?php echo $row['name']; ?></div></td>
so I can visually see the html tables etc etc, makes for easyer editing.

HTH