PHP process all inputs one by one - php

I'm developing an Online Judge as part of my university project. Done setting up the compiler. But the problem is I want to insert all the user inputs in one queue and compile and execute them one by one. This question may seem funny too you but as a noob I don't even know what to write in google search engine. Tried many ways to search in google. Elaborative ways as I should say. Even facebook groups were no help at all.
I repeat my problem again, suppose there are 100 users submitting 100 codes at the same time. I need to put all of them in a single queue then process them one by one.
If you just tell me the name of this procedure that'll be very much helpful. I'll study the rest.
thank you. please don't get offended for such silly question.
regards!

Create a database (mysql or whatsoever) and a table that meets the data you need to store.
For each form submit, store the data in the table.
Run a cronjob task and fetch rows from the database. Mark these rows as "processing" just once you fetch them and "completed" once you process them.
Voila!

Related

Best way to update data in mysql online database

I have an online sql database with a few tables for users matches and bets. When I update the result of any game, I need the status of all bets containing that game in the bet table to be updated. So for example if I update game 8 with the result home win I need all bets which have game 8 in them to be updated as either lost, won or still open.
The way I do this currently is that when the user turns on my android app, I retrieve all the information about the games and all the information about the user's bets using asynctasks. I then do some string comparisons in my app and then I update the data in my database using another asynctask. The issue is that this wastes a lot of computation time and makes my app UI laggy.
As someone with minimal experience with php and online databases, I'd like to ask is there a way to carry out these things in the database itself either periodically (every 3 hours for example) or whenever the data in the gamestable is changed using a php file for example which is automatically run?
I tried looking for some kind of onDataChanged function but couldn't find anything. I'm also not sure how to make a php file run and update data without getting the app involved.
Another idea I had was to create a very simple app which I wouldn't distribute to anyone but just keep on my phone with an update button which I could press and trigger a php file to carry out these operations for all users in my database.
I would appreciate some advice on this from someone who has experience.
Thanks :).
You can easily execute php script periodically if your hosting provider supports script executors like Cron.
About updating game status multiple times, first check tables engine. If you are using engine like InnoDB you can create relationship between those tables, so updating status of one row will affect all connected to them.

How to arrange delete process in project

I have big project where I need to arrange delete of several things like clients, orders, products etc. But theres a point that I need to make an archive for restoring.
So which solution is best.
I have researched and some my ideas were not successful.
1. First was make all rows with status is deleted. But it makes problems in selections and making program work slow.
2. The idea was making separate tables for deleted items but it made problem in orders point as I couldn't manage relations between not deleted orders and deleted clients and products.
Please if theres some ideas how can it be solved ping me.
Well your first idea is kind of the best here. It should'nt make that big kind of problems in selection as you always got the WHERE parameter aviable (though this will take some time and work). Its most easy to restore all of your data then.
And well it shouldnt really slower your programm as databases are build to handle big numbers of data. You should look to optimize your queries first, thats mostly the problem. But like i said your first idea was a good way you were heading
you can add a field in your table call it "visible" that has two values 0 or 1.
then you can use a query like this:
SELECT * FROM tablename WHERE visible=1 // shows all records that has this value, now if you want a record deleted(hidden actually) go to your table and change the field visible of the record to 0, now it won't show on your page but still exist in your table, to show this record again change visible to 1, hope this helps.

current status of mysql table displayed every x seconds

Ok. I didn't know how to put this question in Title so here is a quick description.
Let's say I have site with some promotional stuff to give for free (or not:).
When I have something to give I announce this on facebook and twitter etc. and people can come to website and fill quick form, couple quick questions and of course name and address.
But the problem is I have for example 20 pieces of this thing to give for free.
When you submit the form this goes automatically to database table.
I know how to display current status for this offer with some PHP (like: there's only 12 items left.hurry up!), there is also no problem with refreshing this every couple seconds with AJAX. But problem I see in here is when let's say this will become more popular and I will have many offers during short time.
I don't want database to be overloaded with queries from hundreds of people every two seconds.
Is there any way to send just one query every two seconds (somewhere on the sever?) and just somehow update value from this query in any browser currently visiting the website?
I'm not sure if this is clear question but what I'm asking is what would be the best practice for this kind of situation.
Is my concern about overloading the database even reasonable?
And extra problem...
In this particular situation - with the limit for amount of people that can participate - is there any threat that I can have strange behavior when two people will send form in exactly the same time when there is only one item left?
I would love to see any directions in this subject. Even general one will do :)
PS: No, english is not my first language :)
Thx
Can't you have one script loading from the database and save it somewhere that isn't the database (a file, preferably) and then it can be extracted from there? This will include a cronjob for that script to be run every 5 second.

How to Create Quiz using PHP, MySQL and Jquery

I need to create a quiz/multiple choice questions with correct answer.
Its basically for vocabulary, so 'A definition will be shown' and then possible Words would be provided.
My previous plan: Select word and meaning from Database, then generate the form for answers and then when user answers move on to next word.
I would be selecting words from database randomly, to keep it different each time. Also, I would be noting down how many times the word was answered correctly or incorrectly. So, that later on I can arrange them according to difficulty also.
My Problem: How do I update to the next question when user answers the question? How do I move on to the next problem, I thought I could do it easily using Jquery but integrating Jquery with PHP is tougher than it seems. I searched for plugins but they basically hard code the question in the JS, I wish to take them out from Database which would be updated as required.
Its a pet project, just so that I can help people practice their Vocabulary. I have implemented the basic design and also developed space for people to Contribute their words. The plans for expansion are vast with many possible directions, later, ranking system, facebook integration, etc. etc. I wish to finish it by the end of this weekend, so that I can move on to other things.
You can see vocabulary.dharamveer.in but you would only get idea about the basic application, not much regarding the problem at hand.
Eagerly awaiting your answers, thank you for help in advance :)
ajax is definitely the way to go with this, use ajax with json to load up your questions and then just have jquery loop through them.
Option 1
If you are creating a set length quiz, you could always create the full quiz off the start. That way you can ensure there are no repeating questions without the need to save anything. Then you can just loop through the whole quiz without making a call for each question.
Option 2
If it's a never ending quiz, then maybe you can do the questions in batches. Then when the user is done the old batch you can send that one back as a parameter and exclude them from the new batch. If your batches are large (for example 50 questions), than it would be at the very least 50 questions until a repeat and that's the worst case. Depending on how many questions you have total, you could end up with multiple batches before a repeat.
I would use Ajax to he the next question. Have another page simply retrieve a single random question and retrieve it with jquery Ajax.

Monitor Database Updates Live using AJAX and SQL

How can one trigger an event locally when a field in a connected database changes? I've done some research but it seems like there there are varying and inconclusive answers to the question.
I'm building an application where users rate comments, and I'd like to have the ratings change live when they are modified by a different user. For example: users A and B are both viewing the comment feed. Say user A uprates a comment, causing the "rating" field for that comment's row in my database table to be incremented. Without having a timer for periodic refreshing, I'd like to have user B see the change in comment (updated on his page) as soon as A has rated it. Is there a way to do this using just PHP, SQL, and JavaScript/jQuery, or applicable plugins/libraries?
Examples, ideas, links, etc. all appreciated. Thanks so much for the help.
The technique is called Comet, a play on words to Ajax. There are many ways to accomplish it. See here: http://en.wikipedia.org/wiki/Comet_(programming)

Categories