HOME       >>       Programming

Help With Small Script Required Adding and adjusting data in MySQL


mrdee

A request for help from PHP programmers/specialists on this forum.

I am looking for a small script (unfortunately I am not (yet) fluent enough in PHP to do it myself) to achieve the following:

I use Tanida Quiz Builder to put a quiz on my website.
You can use your own scripts for the scoring/ranking system, and I have already managed to set up a MySQL table, which only needs 3 variables for every participant, they are "Name, "number of times played" (since it is a weekly quiz) and, obviously, "score".

I put some test data in the MySQL table and wrote a small script to display the ranking, and that all seemed to work.

That script looks as follows:

<html><head><title>Quiz Ranking</title></head><body><?php$database="mrdee_reloader";mysql_connect ("localhost", "mrdee_mrdee", "********");@mysql_select_db($database) or die( "Unable to select database");$result = mysql_query( "SELECT * FROM Quiz ORDER by Score DESC" )or die("SELECT Error: ".mysql_error());$num_rows = mysql_num_rows($result);print "<center>";print "<h2>";print "Ranking.<P>";print "</h2>";print "<table width=400 border=1>n";print "<th>"; print"Name"; print "</th>";print "<th>"; print"Number played"; print "</th>";print "<th>"; print"Score"; print "</th>";while ($get_info = mysql_fetch_row($result)){print "<tr>n";print "</center>";foreach ($get_info as $field)print "t<td><font face=arial size=3/>$field</font></td>n";print "</tr>n";}print "</table>n";?><div align="center"><a href="index.htm">Back to the beginning</a></div></body></html>
No problem so far, the data display nicely, and are sorted from highest score down to lowest.
What I need now is a script which, after a participant takes the quiz, adjusts the number of times the participant has taken it by adding 1 to the number of times, and adjusts the score, by adding the new score to the previous.
Obviously, when a participant takes the quiz for the first time, he/she has to be added in the table, along with the relevant data.

Also, is it advisable to do it like I set it up, or is it better to get the name data from another table, called "partic", which contains the first name, last name, username(the one I want to display), email address and password of the participants?
(No problem setting up that table, I do that with "Simfatic Forms", a program that lets me put forms online and saves the entered data in a MySQL database).

I really hope someone can help me, as I need a working script, but it will also help me to learn more about PHP/MySQL.

Thank you in advance.

mrdee

I have began to work out a few things for myself, but I am still far from there.I was wondering if there is a PHP command (some people wight say "look it up", but what if you are not sure what keywords to look under?) which lets you add numbers to a number already in the database?What I mean is:as you can see from the post above, my table has 2 numeric fields, ie. "Number_of_quizzes" and "Score".Now, every time a participant has taken the quiz, these have to be adjusted, the Number_of_quizzes field has to go up by 1, and the Score field has to have the score in the new quiz added to the already existing score (eg. a candidate had 80 points in his score, and in his new attempt scores 20, so, that 20 needs to be added to the already existing 80, making it 100).Hoping for a bit of assistance.


sonesay

Hello, I am not similar with the flash survey tool you are using so I cant help as much. You say you created a separate table of your own to store the count for surveys taken and score. Does this mean that the flash survey tool it self does not store or keep track of this information already? To solve your problem you will need to locate the point where the flash survey does the save or insert to its database table if any. i.e. the end of a survey submission. If I can recall correctly flash can recall or redirect to php files I believe so locating such php files should be a start and you would obviously need to modify it here to do all your logic.


mrdee

Thanks for your input.The program does keep track of scores, but within its own GUI.That means only the one who made the quiz can read the tables.they also have their own space on the net to display the tables, but there is a charge to use that.You can, hovewer, let the program go to a PHP script to put the results in your own MySQL database.And this is what my question is all about: to get help putting that script together.


sonesay

Do you have an example link to show some examples of how it is done? I am asking because I dont have time to search for it maybe if I can see a direct example I can help you out but at this stage I have no idea how the Flash survey works with php.


mrdee

Yes, I do as a matter of fact.
After you have taken the quiz, you get sent to the following place: Quiz Ranking, which shows the ranking of the people who have taken part, with their name, how many quizzes they have taken so far and the total of their score.

The only thing I am looking for is the right PHP code so I wouldn't have to do it all by hand.

Like I said, my problem has nothing at all to do with Flash or anything whatsoever, I know the PHP scripts in conjunction with the program work, I am only looking for the right code to achieve getting the data into the MySQL database, because I am not a fluent PHP programmer (yet, I am working on it).

So, basically, all I want is the PHP code for adding 1 to a number (every time someone takes a quiz, the figure for the number of quizzes they took gets increased by 1), and the code for adding the score of the new quiz to the already existing score (a player had 80 points, takes the new part of the quiz and scores 20, so, that 20 gets added to his previous score, 80, making it 100).

So, basically, all I am looking for is a few lines of PHP code, so I can complete the script.


sonesay

Yes, I do as a matter of fact.After you have taken the quiz, you get sent to the following place: Quiz Ranking, which shows the ranking of the people who have taken part, with their name, how many quizzes they have taken so far and the total of their score.

The only thing I am looking for is the right PHP code so I wouldn't have to do it all by hand.

Like I said, my problem has nothing at all to do with Flash or anything whatsoever, I know the PHP scripts in conjunction with the program work, I am only looking for the right code to achieve getting the data into the MySQL database, because I am not a fluent PHP programmer (yet, I am working on it).

So, basically, all I want is the PHP code for adding 1 to a number (every time someone takes a quiz, the figure for the number of quizzes they took gets increased by 1), and the code for adding the score of the new quiz to the already existing score (a player had 80 points, takes the new part of the quiz and scores 20, so, that 20 gets added to his previous score, 80, making it 100).

So, basically, all I am looking for is a few lines of PHP code, so I can complete the script.


Can you give a full description of all tables involved? i.e the tables used by the Flash survey script and its records. Any other tables you intend to use. This will make writing example code more accurate and also provide us a better understanding of the database.

mrdee

OK then,I can send you a few of the PHP scripts that come with the program.The program also creates an .xml file which is then read back and shown as a result in the program itself.However, the PHP is fully customisable, and all I want to store is the quiztaker's username, number of quizzes taken, and score. I will also upload my display script.Thank you for your help so far.

reportscore.php

savetodisk.php

pipe.php

pipe_db.php

displayqdateng.php


sonesay

OK then,

I can send you a few of the PHP scripts that come with the program.

 

The program also creates an .xml file which is then read back and shown as a result in the program itself.

 

However, the PHP is fully customisable, and all I want to store is the quiztaker's username, number of quizzes taken, and score. I will also upload my display script.

 

 

Thank you for your help so far.

 

Hey thanks for uploading the files. Unfortunately there has always been this problem with me not being able to download files from there.

 

 

Any ideas why it happens?


mrdee

Hey thanks for uploading the files. Unfortunately there has always been this problem with me not being able to download files from there.

 

 

Any ideas why it happens?

 

No idea at all why that could be.

 

Maybe you should check with one of the forum leaders, or maybe send a ticket to Xisto.

As far as I can remember (mind you, I have not worked with attachments on these forums a great deal), it seems to work for me to get the attachments to download/open.

 

Or maybe you might have to check your firewall settings.

 

You can also, if you wish to do so, PM me an email address where I can send the files to (They are not big anyway).

 

In the mean time, thank you for your help so far.


truefusion

I get the same error when trying to download the PHP files. Try putting them all in a ZIP archive and uploading it.


mrdee

Here are the files from the earlier post in .zip format.I must say that the pipe.php and pip_db.php files are in their raw format as they come with the program, for practical reasons, I could not add the modified files, with the login to my MySQL db to the zip file.But if that does not help, let me know and I'll go further with it.Thanks anyway.

reportscore.zip


truefusion

Couldn't find anything in those files that helps me determine what the current user is, so i suppose you'll be dealing with that. Anyway, to add 1 to an integer in a MySQL database, you can use the following syntax:

UPDATE table_name SET column_name1 = column_name1 + 1, column_name2 = column_name2 + 1 WHERE ...

Replace the obvious with their practical parts. The "..." is where you would replace with what row to edit according to what the current user is.


mrdee

OK, thank you for the help so far, everyone.I have had a lot of useful input from my fellow forum visitors here.The funny thing is, now that I think I am getting somewhere, it seems the program itself is beginning to play up, it won't run properly anymore.Even support are ignoring my tickets now, well, if that is their attitude, they know what to do with their software.You might argue, "why didn't you try to get an explanation from support to solve your PHP problem?"Well,of course I tried that, but all I got was answers that either were beside the point, or that had completely nothing to do with my questions. An example: whenever I uploaded a quiz, with the option of letting pipe.php display a report, I was told "files could not be uploaded", while the log showed me it could not upload pipe.php.Yet, when I looked via Filezilla, the appropriate folder was there, and the pipe.php script was in it.It alo said to CHMOD the folder to 777 or 755, which it already was (777, tried 755, didn't work either).As a result, when trying to get a report, it said "cannot connect to the server".After putting that question to support, I was asked to send the quiz source file, which I did.Then, I was sent it back (however, they had made modifications, but did not tell me which ones or how), but still no joy.Then they asked for my upload info, which I then reluctantly gave to them, they uploaded the quiz, and it worked, yet, when I tried myself again, same problem.Me back on to support then, where I got, "I'll upload it again and check your new source file, just to see if you're not making the same mistake again".WHAT MISTAKE????I only followed the instructions, uploaded everything as was required, but kept getting an error message, and, if I did make a mistake, why did they not tell me which one then?Then, as I said, all my further support tickets were just ignored.To some people, people are just good to get and use their stuff, but when they need help, it becomes quite another matter.Anyway, I am thinking of ditching that program now, I have found another one,freeware even, it might not look as flashy, but it does the job. The only thing is, the report system works on a Perl script, which I know even less about than PHP.So, I'll probably be roaming the Perl topic now.However, before I do, "is Perl fully supported by Xisto hosting?", also, is Perl not a bit outdated/old fashioned, or is it still fully and actively used?Anyway, thanks for your help everyone, and should there be any update with the original program, I will let you know.


macware23

I cannot download the files.



REGISTER GET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.