好的,我有一个简单的php select脚本,我有下面的代码来定义变量。
$result = mysqli_query($con,"SELECT * FROM practice_sheets WHERE student_name='$_SESSION[SESS_FIRST_NAME] $_SESSION[SESS_LAST_NAME]'");
$numrows = mysqli_num_rows($result);
$id = $row['id'];
$total_min = $row['total_min'];
$due_date = $row['due_date'];
然后我有:
echo "<td> <a href='account/practiceSheets?id='$id'> <i class='icon-eye-open'> </i> </a> </td>";
这应该是在点击<a>
时将php select脚本中的变量传递给url。
我最终得到的是account/practiceSheets?id=
没有实际ID。我确信这是一个非常简单的事情,我很抱歉,因为我是PHP的新手,也不知道该怎么称呼它才能在搜索引擎中获得可用的结果!如果它有帮助,我的完整代码如下。
<?php
$con = mysqli_connect("50.63.106.47", "usd309bands", "MacBook1!", "usd309bands");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT * FROM practice_sheets
WHERE student_name='$_SESSION[SESS_FIRST_NAME] $_SESSION[SESS_LAST_NAME]'");
$numrows = mysqli_num_rows($result);
$id = $row['id'];
$total_min = $row['total_min'];
$due_date = $row['due_date'];
if ($numrows == 0) {
echo "<div class='alert alert-danger'>";
echo "No Entries, See your instructor for details.";
echo "</div>";
} else {
echo "<table class='mws-table table-striped table-hover'>";
echo "<thead align='center'>";
echo "<tr>";
echo "<th>Sheet Number</th>";
echo "<th>Total Minutes</th>";
echo "<th>Due Date</th>";
echo "<th>View</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody align='center'>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['total_min'] . "</td>";
echo "<td>" . $row['due_date'] . "</td>";
echo "<td> <a href='account/practiceSheets?id='$id'> <i class='icon-eye-open'> </i> </a> </td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
mysqli_close($con);
}
?>
答案 0 :(得分:2)
$result = mysqli_query($con,"SELECT * FROM practice_sheets
WHERE student_name='$_SESSION[SESS_FIRST_NAME] $_SESSION[SESS_LAST_NAME]'");
$numrows = mysqli_num_rows($result);
$id = $row['id'];
看不到$row
的来源。
我认为您忘记将MySQL响应提取到关联的数组中。
(您可以使用mysqli_fetch_assoc()
来完成那个)
这是一个简单的例子:
$result = mysqli_query($con,"SELECT * FROM practice_sheets WHERE student_name='$_SESSION[SESS_FIRST_NAME] $_SESSION[SESS_LAST_NAME]'");
$allRows = mysqli_fetch_assoc($result);
foreach($allRows as $row) {
echo $row['id'].'<br/>';
}
这个应列出数据库请求中的所有ID。
答案 1 :(得分:0)
这个SQL查询可能不会返回任何内容,除非名称存储在您的表中,如此
firstlast
"SELECT * FROM practice_sheets WHERE student_name='$_SESSION[SESS_FIRST_NAME] $_SESSION[SESS_LAST_NAME]'"
你可能想要这样的东西
$_SESSION[SESS_FIRST_NAME] . " " . $_SESSION[SESS_LAST_NAME]
返回类似
的名称最后一次
答案 2 :(得分:0)
我改变了
echo "<td> <a href='account/practiceSheets?id='$id'> <i class='icon-eye-open'></i></a></td>"
到此:
echo "<td> <a href='account/practiceSheets?id=" . $row["id"] . "'> <i class='icon-eye-open'> </i> </a> </td>";
并获得了预期的结果!