Linking a row to diplay further information

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
I've got a list of names. I want to make the names a link, that will go to a second page which will display much more info about that name (more information from that same row - according to id field). I'm new and I've been trying a bunch of stuff for hours and I'm just not getting it right. Rather than show you what I've failed at, here's a simplified version of my code. How do I do this?

Code:
<?php

$db = mysql_connect("localhost", "user", "password");
mysql_select_db("database");

$query = "SELECT * FROM alumni ORDER BY lastname";
$result = mysql_query ($query);

if (@mysql_num_rows($result)) 
{ 
print "<table border=1>\n";

while($row = mysql_fetch_array($result)) { 
print "<tr>\n"; 

print "<td><a href=\"newpage.php?id=$id\">".$row['lastname']."</a></td>\n"; 

print "<td>".$row['firstname']."</td>\n"; 
print "</tr>\n"; 
} 
} 
else { 
echo "Sorry, no records were found!"; 
} 

print "</table>\n";

Thanks for helping! :wink:
 
I presume the id var is actually $row['id'] ? Try this:
Code:
<?php

$db = mysql_connect("localhost", "user", "password");
mysql_select_db("database");

$query = "SELECT * FROM alumni ORDER BY lastname";
$result = mysql_query ($query);

if (@mysql_num_rows($result)) 
{ 
print "<table border=1>\n";

while($row = mysql_fetch_array($result)) { 
print "<tr>\n"; 

print "<td><a href=\"newpage.php?id=".$row['id']."\">".$row['lastname']."</a></td>\n"; 

print "<td>".$row['firstname']."</td>\n"; 
print "</tr>\n"; 
} 
} 
else { 
echo "Sorry, no records were found!"; 
} 

print "</table>\n";
 
Back
Top