我想在沒有刷新的情況下寫入DataBase後更新html表的兩行。現在一切正常,除非這件事,我必須刷新頁面才能看到表中的修改值。如何更改已顯示的變量?
這裏是我的網頁:
first.php
<?php
require_once('config.php');
$id=$_GET['id'];
$sql="SELECT S.ID_student, C.name, D.h-theory, D.h-practice FROM students as S, students_details as D WHERE D.ID_student=C.ID_student AND S.ID_student=$id";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo'</br></br>
<table class="my-tabel">
<tr><td>Student name</td><td>'.$row['name'].'</td></tr>
<tr><td>Hours of practice/td><td>'.$row['h-theory'].'</td></tr>
<tr><td>Hours of theory</td><td>'.$row['h-practice'].'</td></tr>
</table>';
?>
<form action="javascript:void(0);" method="post">
<label>Hours of practice:    </label> </td> <td><input type="text" id="practice" class="text" name="h_practice"/>
<label>Hours of theory:</label> </td> <td> <input type="text" id="theory" class="text" name="h_theory"/>
<input type="submit" class="send-h" value="Submit">
</form>
<script>
$('.send-h').click(function(){
$('.send-h').fadeOut();
var practice = false;
var theory = false;
practice = $('#practice').val();
theory = $('#theory').val();
var id = <?php echo json_encode($id) ?>;
jQuery.get('add.php?practice='+practice+'&theory='+theory+'&id='+id, function(data,self){
});
});
</script>
add.php
<?php
require_once('config.php');
$id=$_GET['id'];
$practice=$_GET['practice'];
$theory=$_GET['theory'];
$sql="UPDATE `student_details` SET `ore_practice`='$practice', `ore_theory`='$theory' WHERE ID_student='$id'";
$result = mysql_query($sql);
?>
預先感謝您!
使用AJAX發送正在發送的數據做數據庫。 – iBrazilian2
呃...顯然有一些人認爲他們可以破譯你的意思,因爲他們發佈了答案,但我甚至不能解析「現在一切工作正常,除非這件事,我必須刷新頁面才能看到表中的修改值「更別說弄清楚你的意思了。請更清楚地重申這個問題,我會提名重新開放。 –