正如标题所说,当我用我的第二种形式(attendanceOut.php)创建一个带有mysqli查询的下拉列表时,我没有得到任何项目。我已经从我的attendance.php中的前一个下拉框中提取了一些信息,据我所知可以正常工作。我确定这与从INNER JOIN中提取的这个事实有关,但我无法找到我在语法上搞砸的地方。任何帮助将不胜感激。所以没有进一步的代码。
<?php
$course = $_GET["CourseName"];
$startTime = $_GET["BeginTime"];
$course = trim($course);
$course = strip_tags($course);
$startTime = trim($startTime);
$startTime = strip_tags($startTime);
?>
<html>
<meta http-equiv="Content-Type" content="text/html"; charset=utf-8">
<body>
<?php
$mydbconn = new mysqli("www.evilscriptmonkeys.com", "capstone", "capstone","attendance");
if (mysqli_connect_errno())
{
printf("connection failed: %s\n", mysqli_connect_error());
}
if ($_GET['action'] == 'Create Form')
{
//$result = mysqli_query($mydbconn, "SELECT * FROM student WHERE CourseName = ' " .$course."'");
$c =$course;
$s = $startTime;
$sql = ("SELECT * FROM student WHERE CourseName = '$c' AND Time > '$s'");
$result = $mydbconn->query($sql);
printf ($course);
printf ($startTime);
echo '<table border="1">';
$classFields = $result->fetch_fields();
foreach ($classFields as $classData)
{
echo "<th> $classData->name </th>";
}
while ($row = $result->fetch_assoc())
{
echo "<tr>";
foreach($row as $col=>$val)
{
echo "<td> $val </td>";
}
echo "</tr>";
}
}
?>
<form method = "get" action="changeID.php">
Student Name: <select Name='UserName'>
<option value = "">---Select---</option>
<?php
if ($_GET['action'] == 'Edit Student ID')
{
$c =$course;
$result = mysqli_query($mydbconn, "SELECT s2.UserName
FROM student s1
INNER JOIN students s2
ON s1.UserName = s2.UserName
WHERE s1.CourseName = '$c'");
while(($row = mysqli_fetch_assoc($result)))
{
echo "<option value=\" " . $row['s2.UserName'] . "\">". $row['s2.UserName'] . "</option>";
}
}
?>
</select>
<input type="submit" name="action" value="Change" />
</body>
</html>
答案 0 :(得分:1)
您可以使用别名,然后在数组中使用别名进行访问:
<?php
if ($_GET['action'] == 'Edit Student ID')
{
$c =$course;
$result = mysqli_query($mydbconn, "SELECT s2.UserName AS UserName
FROM student s1
INNER JOIN students s2
ON s1.UserName = s2.UserName
WHERE s1.CourseName = '$c'");
while(($row = mysqli_fetch_assoc($result)))
{
echo "<option value=\" " . $row['UserName'] . "\">". $row['UserName'] . "</option>";
}
}
?>
希望得到这个帮助。