我试图让 mysql 查询的某个单元格成为我最终将创建的用户配置文件的超链接。我可以将所有内容都作为链接,而不仅仅是名称字段。现在我只是为了测试目的而显示所有链接到主键(playerID)的东西。
我知道问题出在这里:if (($cell->name)=='fName')
<?php
// db login info
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db_login.php';
// connecting, selecting, & error messages
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($db))
die("Can't select database");
// get parsed playerID
$id = $_GET[id];
$result = mysql_query("SELECT *
FROM players p
LEFT JOIN baseball b ON p.playerID = b.playerID
LEFT JOIN hockey h ON p.playerID = h.playerID
LEFT JOIN football f ON p.playerID = f.playerID
WHERE p.playerID = '$id';");
if (!$result) {
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<table border='1' cellpadding='1'><tr>";
// printing column headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td><b>{$field->name}</b></td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";
foreach($row as $cell){
if (($cell->name)=='fName'){
echo "<td><a href=\"info.php?id={$row[0]}\">$cell</a></td>";
}
else {
echo "<td>$cell</td>";
}
}
echo "</tr>\n";
}
echo "</table>";
// clear result variable
mysql_free_result($result);
mysql_close($result);
echo "<a href=\"testing.php\">Back</a>";
?>