我应该在此查询中输入if? 我希望如果查询返回为空,则表单不会显示,但只显示类似于&#34的消息;表格中有更正的信息" php很难做到这一点吗?
这是代码:
//Step 2: Kjør en SQL-query to databasen
$sql = "SELECT * FROM oppgave WHERE modulid=4 AND resultat is NULL ORDER BY RAND() LIMIT 1";
$data = null;
$dataid = null;
$result = mysql_query($sql, $tilkobling);
echo "<hr>";
while ($nextrow= mysql_fetch_assoc($result)){
echo "Besvarelse: " . $nextrow['besvarelse'];
echo "<br>Modulid: " . $nextrow['modulid'];
//echo "<br>student: " . $nextrow['studentid'];
echo "<br>";
$data = $nextrow['modulid'];
$dataid = $nextrow['id'];
}
//Skjema til utfylling mot database
echo '<form name="input" action="tilretting.php" method="post">';
echo'Retter<input type="text" name="correctedby" value="'.$_SESSION['myusername'].'">';
echo '<input type="hidden" name="resultat" value="0">';
echo 'Godkjent<input type="checkbox" name="resultat" value="1">';
echo 'modul<input type="text" name="modulid" value="'.$data.'">';
echo 'id<input type="text" name="id" value="'.$dataid.'">';
echo '<input class="levermodulknapp" type="submit" name="lever1" value="Send inn retting">';
echo "</form>";
echo "<hr>";
?>
答案 0 :(得分:0)
答案 1 :(得分:0)
在您的情况下,您应该只能查看$data
和$dataid
变量,例如
if($data != null && $dataid != null){
echo '<form name="input" action="tilretting.php" method="post">';
echo'Retter<input type="text" name="correctedby" value="'.$_SESSION['myusername'].'">';
echo '<input type="hidden" name="resultat" value="0">';
echo 'Godkjent<input type="checkbox" name="resultat" value="1">';
echo 'modul<input type="text" name="modulid" value="'.$data.'">';
echo 'id<input type="text" name="id" value="'.$dataid.'">';
echo '<input class="levermodulknapp" type="submit" name="lever1" value="Send inn retting">';
echo "</form>";
echo "<hr>";
}else{
echo "there is noting to correct in the table";
}