我是PHP和Mysql编程的新手,我想知道在表单中显示数据时是否可以访问另一个数据库行。
以下是代码:
$mysql_host = "";
$mysql_database = "";
$mysql_user = "";
$mysql_password = "";
$con = mysqli_connect($mysql_host, $mysql_user, $mysql_password, $mysql_database);
$result = mysqli_query($con, "SELECT * FROM Elev WHERE Clasa = '" . $_SESSION['clasa'] . "' ORDER BY Nume ASC ");
$result2 = mysqli_query($con, "SELECT * FROM M_Profesori WHERE ID = '" . $_SESSION['ID_p'] . "' ");
while ($row2 = mysqli_fetch_array($result2)) {
while ($row = mysqli_fetch_array($result)) {
echo "<select>
<option value='" . $row2["Materia"] . "'>" . $row2["Materia"] . "</option>
<option value='" . $row2["Materia"] . "'>" . $row2["Materia"] . "</option>
</select>";
}
}
在第二个选项(<option value='" . $row2[Materia] . "'>" . $row2[Materia] . "/option>
)中,我想访问下一个数据库行,而不是这个行。这可能吗?
答案 0 :(得分:1)
如果我已经理解,你可以试试这个:
$row2 = mysqli_fetch_array($result2);
foreach($row2 as $key => $value) {
...
<option value='" . $row2[$key+1][Materia] . "'>" . $value . "</option>
...
}
试试这个......
在adicional,看看这个: 您可以使用模板来构建更好的编码。 (葡萄牙语网站) http://raelcunha.com/template.php
http://raelcunha.com/packages/extra/template/pt-br/api/index.php