我想做一个页面显示一些人名,每个人名都有id,用户点击人名则进入人名具体信息。
问题是现在点击的信息不能识别,无法通过id的传递进入人名的具体信息,
代码如下,希望高手帮忙,谢谢<html>
<head>
<title>Student Info</title>
</head>
<body>
<?php
function usetable($result)
{print "<h1>Student Infornamtion</h1>\n";
print "\n<table>\n<tr>\n" .
"\n\t<th>ID</th>" .
"\n\t<th>Last Name</th>" .
"\n\t <th>First Name</th>" .
"\n</th>"; if($conn = mysql_connect('localhost',DB_USER_NAME, DB_PASSWORD)){ print "<p>Successfully connected to MySQL!</p>"; mysql_select_db("clin2",$conn);
$sql=mysql_query("select userID from user");
$a=$myrow[userID];
$result = mysql_query("select LName, FName from user");
while($row = @ mysql_fetch_row($result)){
print "\n<tr>";
foreach($row as $data)
print "\n\t<td><a href=test3.php?a=$a> {$data} </a></td>";
print "\n</tr>";
}
print "\n</table>\n"; mysql_close();
} else {
print '<p style="color:red;">Could not connect to MySQL.</p>';
}
}
usetable($result);?>
</body>
</html>接受的代码如下<html>
<head>
<title>Student Info</title>
</head>
<body><?php
if($conn = mysql_connect('localhost',DB_USER_NAME, DB_PASSWORD)){ print "<p>Successfully connected to MySQL!</p>"; mysql_select_db("clin2",$conn);$sql="select * from user where id = $_GET[a]"; print "\n<tr>";
print "\n\t<td> {$sql} </td>";
print "\n</tr>";?>
</body>
</html>
问题是现在点击的信息不能识别,无法通过id的传递进入人名的具体信息,
代码如下,希望高手帮忙,谢谢<html>
<head>
<title>Student Info</title>
</head>
<body>
<?php
function usetable($result)
{print "<h1>Student Infornamtion</h1>\n";
print "\n<table>\n<tr>\n" .
"\n\t<th>ID</th>" .
"\n\t<th>Last Name</th>" .
"\n\t <th>First Name</th>" .
"\n</th>"; if($conn = mysql_connect('localhost',DB_USER_NAME, DB_PASSWORD)){ print "<p>Successfully connected to MySQL!</p>"; mysql_select_db("clin2",$conn);
$sql=mysql_query("select userID from user");
$a=$myrow[userID];
$result = mysql_query("select LName, FName from user");
while($row = @ mysql_fetch_row($result)){
print "\n<tr>";
foreach($row as $data)
print "\n\t<td><a href=test3.php?a=$a> {$data} </a></td>";
print "\n</tr>";
}
print "\n</table>\n"; mysql_close();
} else {
print '<p style="color:red;">Could not connect to MySQL.</p>';
}
}
usetable($result);?>
</body>
</html>接受的代码如下<html>
<head>
<title>Student Info</title>
</head>
<body><?php
if($conn = mysql_connect('localhost',DB_USER_NAME, DB_PASSWORD)){ print "<p>Successfully connected to MySQL!</p>"; mysql_select_db("clin2",$conn);$sql="select * from user where id = $_GET[a]"; print "\n<tr>";
print "\n\t<td> {$sql} </td>";
print "\n</tr>";?>
</body>
</html>
$a=$myrow[userID]; $result = mysql_query("select LName, FName from user"); while($row = @ mysql_fetch_row($result)){
print "\n <tr>";
foreach($row as $data)
print "\n\t <td> <a href=test3.php?a=$a> {$data} </a> </td>";
print "\n </tr>";
}
print "\n </table>\n";
这段代码有问题.
我猜测,这个id,LName,FName应该是一一对应的才对,所以你前两句等于是无效的.
$result = mysql_query("select userID LName, FName from user"); while($row = @ mysql_fetch_row($result)){
$userid = $row[0];
print "\n <tr>";
foreach($row as $data)
print "\n\t <td> <a href=test3.php?a=$userid> {$data} </a> </td>";
print "\n </tr>";
}
$userid = $row[0];
unset($row[0]);
print "\n <tr>";
foreach($row as $data)
print "\n\t <td> <a href=test3.php?a=$userid> {$data} </a> </td>";
print "\n </tr>";
}
<head>
<title>Student Info</title>
</head>
<body>
<?php
function usetable($result)
{print "<h1>Student Infornamtion</h1>\n";
print "\n<table>\n<tr>\n" .
"\n\t<th>Last Name</th>" .
"\n\t <th>First Name</th>" .
"\n</th>"; if($conn = mysql_connect('localhost',DB_USER_NAME, DB_PASSWORD)){ print "<p>Successfully connected to MySQL!</p>"; mysql_select_db("clin2",$conn);
$result = mysql_query("select LName, FName from user");
$res = mysql_query("select userID from user"); while($row = @ mysql_fetch_row($result)){
$rowa = mysql_fetch_row($res);
$userID = $rowa[0];
print "\n <tr>";
foreach($row as $data)
print "\n\t <td> <a href=test3.php?ID=$userID> {$data} </a> </td>";
print "\n </tr>";
}
mysql_close();
} else {
print '<p style="color:red;">Could not connect to MySQL.</p>';
}
}
usetable($result);?>
</body>
</html>但是接受页显示不出结果,不知道什么问题,
接受页如下<html>
<head>
<title>Student Info</title>
</head>
<body><?php
if($conn = mysql_connect('localhost',DB_USER_NAME, DB_PASSWORD)){ print "<p>Successfully connected to MySQL!</p>"; mysql_select_db("clin2",$conn);$sql=mysql_query("select * from user tablename where ID = $_GET[ID]"); $array=@mysql_fetch_array($sql);echo $array[ID];}
?>
</body>
</html>
大概是这个样子吧