1
我一直在研究一個調查系統,該調查系統從數據庫中讀取記錄(按「章節」排序的問題,您將會看到我的意思),併爲每條記錄添加一個分數。問題存儲在一個數組中。所以一個記錄可以容納例如五個問題。讓我們深入到代碼PHP分別識別每條記錄
//echo the question list from the database
$query_questions = mysql_query("SELECT * FROM `vraag`");
while($result = mysql_fetch_array($query_questions))
{
//displaying the questions
echo "<br /><br /><b>";
echo $result['header']. "</b><br />";
echo $result['beschrijving']. "<br /><br />";
echo $result['onderwerp']. "<br />";
$aantal = $result['aantal_vragen'];
$id = $result['id'];
echo "<input type='hidden' id='number_of_questions' value=".$aantal." mousedown='calculate_score(this.value,0)'/>";
$array = unserialize($result['vraag']);
//retrieve the content from the array
for($i = 0; $i < $array; $i++)
{
foreach($array as $value)
{
$array = $value;
echo "<form><table><td>". $array ."</td>";
echo "
<td>1<input type='radio' name='vraag[]' value=1 onclick='calculate_score(".$aantal.",this.value)'/></td>
<td>2<input type='radio' name='vraag[]' value=2 onclick='calculate_score(".$aantal.",this.value)'/></td>
<td>3<input type='radio' name='vraag[]' value=3 onclick='calculate_score(".$aantal.",this.value)'/></td>
<td>4<input type='radio' name='vraag[]' value=4 onclick='calculate_score(".$aantal.",this.value)'/></td>
<td>5<input type='radio' name='vraag[]' value=5 onclick='calculate_score(".$aantal.",this.value)'/></td></table></form>";
}
echo "Uw totaal score is: <span id='total_score[]' ></span>";
break;
}
}
什麼不順心的是,它使用查詢來計算與價值的最後一個記錄,它忽略了第一條記錄和第二,因此只挑選了最後(第三)記錄我希望它爲每個記錄指定一個分數,這樣很快就會被抽出。無線電元件的一點是要做出點系統排名從1到5,所以它看起來像:問題1-2-3-4-5 這是我的本意 [記錄1] 得分
[記錄2] 得分
[記3] 得分
但目前它是這樣工作的 [記錄1]
[記錄2]
[記錄3] 得分
我不完全確定break命令,但是我測試它是否能解決我的問題。對於得分標籤,我知道我應該在每次填充數組時增加一個數組,但我不知道語法或者甚至可能根本就不這樣做。 我是新來堆棧溢出,所以原諒我任何缺失的標籤或任何其他不可讀或不愉快的眼睛。
謝謝你指出,我很感激。 – 2012-04-27 09:02:01