好的,我正在學習網站上工作,並且遇到了一個很大的障礙,我在過去的幾天裏一直無法克服,儘管試圖通過這個工作讓我通過其他一些障礙,我現在卡...來自MySQL的Javascript數組
如果有人知道任何教程或任何會非常有用的東西,我發現很難找到教程來幫助我,我可以找到點點滴滴,但沒有什麼已經能夠幫助我找出解決方案。
我想要發生的事情: 當人進入課程頁面時,它將從問題列表中拉出5個項目,並一次將它們呈現給人員1,當他們按下輸入時,它將他們帶到下一個項目,當他們已經通過5件物品時,它將離開該頁面。
什麼工作: 拉5問題ID的使用MySQL
什麼我需要: 把5問題的ID爲基於第一序列號 JavaScript的箭頭 將數據加載到頁面迭代通過數組裝載數據到頁面沒有總刷新
這是lesson.php頁面我到目前爲止,減去我已經嘗試過的只是代碼片段和這樣我發現從stackoverflow,我試圖使我的設置工作:
<!doctype html>
<?php
include ("Connections/localhost.php");
//Get up to five questions that user hasn't seen
$sql = "SELECT quest_id FROM questions LEFT OUTER JOIN answers ON questions.quest_id = answers.ans_question WHERE answers.ans_question IS null and questions.quest_level <= (SELECT user_level FROM users WHERE username = '".$_SESSION['username']."' LIMIT 5);";
$qresult = mysql_query($sql);
//Get number of lessons available
$result = mysql_query("SELECT COUNT(*) AS total FROM questions LEFT OUTER JOIN answers ON questions.quest_id = answers.ans_question WHERE answers.ans_question IS null and questions.quest_level <= (SELECT user_level FROM users WHERE username = '".$_SESSION['username']."');");
$les = mysql_fetch_assoc($result);
?>
<html>
<head>
<meta charset="utf-8">
<title>Lesson</title>
<script>
function play_audio() {
document.getElementById('id1').play();
}
var lessons = <?php echo $les['total']; ?>;
var i = 1;
if(lessons > 5) {
lessons = 5
}
function next_question() {
if(i<lessons) { //if there are still reviews to do
//call webpage to get new information
i++;
}
else {
//Load finished page
}
}
</script>
<link href="review.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="text_display">
<p><?php echo "Question Appears Here" ?></p>
</div>
<div id="looking">
What is the <?php echo "Meaning?" ?>
</div>
<div id="input_bar">
<form>
<input type="text" name="textfield" id="txt_input">
</form>
</div>
<div id="audio">
<form>
<input name="audio" type="button" id="btn_audio" value="Audio" onClick="play_audio()">
</form>
</div>
<div id="info">
<audio id="id1" src="audio/" style="display:none"></audio>
<h2>Information</h2>
<p></p>
</div>
</body>
</html>
我有一個getitem.php頁面,它將從數據庫中提取選定的問題信息,以便我可以從中提取信息並更新課程頁面而無需重新加載它。
<?php
include ("Connections/localhost.php");
//Get item from url
$question = $_GET["ans_question"];
//Make sure to get UTF-8
$change = "SET NAMES 'utf8'";
mysql_query($change) or die("The change did not work: $change");
//Pull that question from the database
$sql = mysql_query("SELECT * FROM questions WHERE quest_id = '".$question."'");
$item= mysql_fetch_assoc($sql);
?>
<html>
<meta charset="utf-8">
<body>
<div id="text"><?php echo $item['quest_text']; ?></div>
<div id="type"><?php $qtype = $item['quest_type']; echo $qtype ?></div>
<div id="question"><?php echo $item['quest_question']; ?></div>
<div id="answer"><?php $ans = $item['quest_ans']; echo $ans?></div>
<div id="qaudio"><?php $qaudio = $item['quest_audio']; echo $qaudio?></div>
<div id="qinfomation"><?php echo $item['quest_info'];?></div>
</body>
</html>
所以你想要從getitem.php傳輸數據(5個問題)到lesson.php? – stackErr
是的,這是我的問題之一,我需要將變量傳遞給該頁面,雖然它會像localhost/getitem.php?ans_question = 1 – chris3spice
對於初學者,我強烈建議您不再使用'mysql_query'和原始MySQL API的其他相關功能,因爲它們現在已從PHP中折舊。我的建議是使用PDO或mysqli,因爲它們在最新版本的PHP中均受支持,並且更安全。 – SteppingHat