Reputation: 1
I am new to PHP and Mysql programming and I would like to know if I can access another database row when showing data in a form.
Here is the code:
$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>";
}
}
In the second option (<option value='" . $row2[Materia] . "'>" . $row2[Materia] . "/option>
) I would like to access the next database row, not this one. Is this possible?
Upvotes: 0
Views: 174
Reputation: 388
If I've understood, you can try this:
$row2 = mysqli_fetch_array($result2);
foreach($row2 as $key => $value) {
...
<option value='" . $row2[$key+1][Materia] . "'>" . $value . "</option>
...
}
try this...
In adicional, look this: You can use a template to build better codification. (site in portuguese) http://raelcunha.com/template.php
http://raelcunha.com/packages/extra/template/pt-br/api/index.php
Upvotes: 1