Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Alright, I'm working on a learning website and have come to a big obstacle I haven't been able to get over for the past few days, though trying to work through this got me through some other obstacles, I'm now stuck...

If anyone knows any tutorials or anything that would be extremely helpful, I'm finding it hard to find tutorials to help me out, I can find bits and pieces but nothing that has been able to help me figure out a solution.

What I want to happen: When the person goes to the lesson page, it will pull 5 items from the question list and will present them to the person 1 at a time, when they press enter it takes them to the next item, when they've been through 5 items it will leave the page.

What does work: pulling 5 question ID's using MySQL

What I'm needing: Putting the 5 question ID's into javascript arrow Load data into page based on first array number Iterate through array loading data onto page without a total refresh

This is the lesson.php page I have so far, minus the few things I've tried which were just code snippets and such I found from stackoverflow that I tried to make work with my setup:

<!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>

I have a getitem.php page that will pull the selected question info from the database so that I can pull info from it and update the lesson page without having to reload it.

<?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>
share|improve this question
 
So you want to transfer data(5 questions) from getitem.php to lesson.php? –  stackErr Jan 25 at 1:07
 
Yes, that's one of my issues, I need to pass the variable to that page though so it'd be like localhost/getitem.php?ans_question=1 –  chris3spice Jan 25 at 1:09
 
For starters, I would highly recommend that you no longer use mysql_query and other related functions of the original MySQL API as they are now depreciated from PHP. My recommendation would be to use PDO or mysqli instead as they are both supported in the latest version of PHP and are much more secure. –  SteppingHat Jan 25 at 1:16
 
Aww no more mysql_query... Like I said in another commend the last time I used php was Version 2... –  chris3spice Jan 25 at 1:26
add comment

1 Answer

It will do you a lot of good to use a framework like laravel to help you simplify things though if you are new to php and web development in general, it will make sense play around with core php propgramming and mysql queries. Laravel on the other is very easy to learn and simple to install. With that said you could also decide to return your resultset from mysql a json data to you webpage and using jquery to capture it.

What you should be looking at is how to build Ajax application and for this i highly recommend using Jquery library.

share|improve this answer
 
Thanks I'll check it out, I'm not new to it, its just been years since I've used php... version 2 was the brand spanking new version when I last did web development, I've done a basic javascript class but its been almost no help here. –  chris3spice Jan 25 at 1:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.