macaframa3 Posted October 8, 2010 Share Posted October 8, 2010 -First I want to say that I love this site and always check google before I submit questions but im lost. I'm into security and trying to learn a little Apache, Mysql, and PHP to understand the development cycle better. As practice im creating a notecard test review site. Create notecard Decks, add/delete questions etc. shuffle, then test yourself. I though I was doing good until I got to the page that shows the questions (test.php). Right now I pass the "deck_id" field in a GET to a "test.php?id=" page that runs a script that pulls out all the questions for that deck from my "questions" table and loops to show each question for that "deck". My loop works, (gets array from database and shows questions one by one), but it writes all the questions to the page at the same time. DUH. I want it to show one question with a "NEXT" button to show next question. This button clears the first question and writes the next one until they are all done. No grading or anything needed. Is there a way to do this gracefully? I dont know much javascript but looked up innerHTML and see i can update text that way but the PHP loop I have goes so fast it just end up showing the last question with no way to pause it between questions. Can anyone think of a way to do this? My problem is passing the data from page to page to page (I lose the array data) If this is impossible my other thoughts are: 1) store current list of Q/A's in cookie (OR) 2) pass Q/A to another page with POSTS (OR) 3)store Q/A's to temporary sql table and use GETS in loop to show each one by one. "testing.php?question=1" 4) can i set a global variable that can pass the data to separate pages? 5)user iFrame so it looks like one page (dont know how) Im leaning to number 3 but want to hear your suggestions. (sorry very new) Quote Link to comment Share on other sites More sharing options...
Pawn Posted October 9, 2010 Share Posted October 9, 2010 Use a second querystring argument. // Construct query $sql = "SELECT * FROM questions WHERE deck_id = ".$_GET['id']; if(isset($_GET['question'])) { // Append condition if question_id was provided $sql .= " AND question_id = ".$_GET['question']; } // Display relevant question if(!$query = mysql_query($sql)) { echo mysql_error(); die(); } $row = mysql_fetch_assoc($query); print_r($row); // Construct "next" link (or form action) $sql = "SELECT question_id FROM questions WHERE deck_id = ".$_GET['id']; if(isset($_GET['question'])) { $sql .= " AND question_id > ".$_GET['question']; } $sql .= " ORDER BY question_id LIMIT 1"; if(!$query = mysql_query($sql)) { echo mysql_error(); die(); } $row = mysql_fetch_assoc($query); $next_link = $_SERVER['PHP_SELF']."?id=".$_GET['id']."&question=".$row['question_id']; echo " <a href=\"".$next_link."\">Next</a>"; Untested. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.