php foreach result it's own page? - php

I am building a quiz and I would like to have each page be it's own question, and when the user selects an answer, he gets feedback on if he was correct or not before proceeding to the next question. At the end of the quiz, I want to show their answers in summary.
There is not specific number of question to each quiz, so I need to find a way to know when to finish the quiz.
My thoughts so far are :
1 - count the number of questions in the database -> save to global[num_question]
2 - create counter variable that increments each time a user answers a question
3 - some if logic for when the counter is 0, finish the quiz and display a summary.
Am I overthinking this? I am using codeigniter if that helps

Related

Laravel view more link pass id

Hello I am using laravel 5 to display a 20 column csv from my database, I have a foreach loop displaying 5 of the 20 columns in a table and then a view more button to take you to another page with a table showing all the information of that particular row depending on the id.
My question is how do I pass the id to the other page so I can do another foreach loop to display the rest of the info? I have it so when you hover over the link it's display the id. I know this is vague so if you could point me in the right direction it would be much appreciated as I'm not home at the minute so I can't post my code, thanks!
What you are looking for is called pagination and lucky for you Laravel has made a beautiful function to make this easier documented at https://laravel.com/docs/5.4/pagination.

Gravity Forms Personality Quiz Add-On

I'm trying to figure out how to hack this plugin Gravity Forms Personality Quiz Add-on. (https://wordpress.org/plugins/gravity-forms-personality-quiz-add-on/)
Basically I've created 4 fields in ACF to add more "weight" to specific questions within the quiz, to essentially 'force' a tiebreaker rather then use the random option tie breaking function the plugin comes with. Within the backend ACF fields we store the numbers of the questions in order of importance (ie. field one has the number 2 in it to denote that question 2 is the most important question in the event of a tiebreaker).
Each answer has a specific letter value associated with it N,I,S or D. In the event of a tie (ie. same number of "N's" & "I's" chosen) the code should cycle through and see if first tiebreaker question (question 2 in this case) has a value of either N or I. If so, then that letter would be the final result. If neither N or I was chosen for question 2 the tiebreaker code should then move on to the next highest weighted question and preform the same test, and so on.
Problem is that it only seems to work for the first quiz and ONLY "Your Love Style Quiz" the partner quiz doesn't work at all.
If anyone has any suggestions on how to get this working please let me know.
Here is the link to the thread and my code: https://wordpress.org/support/topic/tie-breakers-via-acf/
Got this working, seems that having questions prior to the quiz questions were interfering with the quiz results. By moving them to the bottom, the tiebreakers now work as expected.

Codeigniter linking pages to each other [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This may be a bit confusing to you but I'll try to make it as simple as possible.
I am working on a simple project where I have only one type of content coming from my database. When a user lands on my website they will be seeing one of random entries as home page view and then they will be able to click on next and previous to see other available pages.
It may work like pagination, but the difference is that pagination pulls all entries from database and lists them based on number of listing per page. My approach is the exact article page to have only next article and previous article links on every page.
Would you please let me know how would you approach this if it was your application? I'm looking forward to hearing your thoughts.
Thank you.
you have to build a query which returns max three rows - one for prev data, one for current data and another one for next data.
Now you have to check if prev data not found in the query result then do not show prev link in the page
Also you have to check if next data not found in the query result then do not show next link in the page.
Query for first page will return two rows and for next page onwards will return three rows. for last page query will return two rows.
Depending on the which links getting clicked you have to build the query.
For first page you return the query with first and next records from the db. from next page onwards you have to get the clicked link's id and determine the prev and next data for next page onwards.

Displaying questions in a questionnaire using PHP?

I am building an online questionnaire. In this questionnaire, the user should see only one question at a time per page. When he sees the question, he will provide an answer and after that he will press on next to go to the second question and so on until the end of the questionnaire. I have already built the questionnaire but I am stuck now on the part" how i can display only one question from the database?". Also, when the user press on next, should i save the answer immediately to the database or I should wait until he completes answering all the questions and save them at the end to the database?
If anyone can help in that, please provide me with the appropriate technique to do that in PHP.
Use a counter variable that matches all the question ids (hope you have unique ids for each of your question).
And then loop through that variable and for each counter value fetch the data from the database using where id = ? clause where ? will be replaced by the counter variable value.

How to create a voting system with AJAX? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
jQuery voting system
I've been using this tutorial to create a voting system.
The problem is that on the tutorial the votes update because he can just echo out the votes into the same place if that makes sense. But what if I had an image triggering the vote and I wanted to then update the votes which were somewhere else on the page?
For example, his "button" to vote up holds the amount of votes up, but I want to hold that data somewhere else but don't know how to auto update it once the vote has been completed.
Also, my image always disappears when I click it, how can I stop that?
I would post the code, but it's basically the same as the tutorial only changed for my own needs.
Say you want to update the results in a new <div id="new-results">.
Using the same code inside the
$(".vote").click(function(){ /* his code here */ });
you'll want to replace
parent.html(html);
with
$("#new-results").html(html);
in both places where the parent is referred to.

Categories