Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Linking a row to diplay further information

Codes here !

Moderators: macek, egami, gesf

Linking a row to diplay further information

Postby Fife Club » Tue Oct 15, 2002 9:13 pm

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: Select all

<?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:
User avatar
Fife Club
New php-forum User
New php-forum User
 
Posts: 15
Joined: Wed Oct 09, 2002 7:50 pm
Location: Charlotte, NC, USA

Re: Linking a row to diplay further information

Postby Jay » Tue Oct 15, 2002 10:45 pm

I presume the id var is actually $row['id'] ? Try this:
Code: Select all

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

Jay
 


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.