ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would like to compare MatchData.homescore with PredictionData.homescore and MatchData.awayscore
with PredictionData.awayscore. If the results are the same give the user 3 point, but if the results are different give 1 point.
Something like:
3 point if the user predict 3-1 and the result is 3-1
1 point if the user predict 1-1 and the result is 2-2
$sql = "SELECT MatchData.homescore, PredictionData.homescore, MatchData.awayscore, PredictionData.awayscore FROM MatchData, PredictionData WHERE MatchData.homescore=PredictionData.homescore AND MatchData.awayscore=PredictionData.awayscore";
$result = mysql_query($sql, $connection_id);
if( mysql_num_rows($result) ) { give user 3 point; } else { give user 1 point; }
Distribution: Slackware 9.x, Knoppix, Damn Small Linux, RedHat.
Posts: 465
Original Poster
Rep:
Thanks all for your reply's. I was looking and you have the idea, but the poblem is that each user can have a lot of predictions. I was trying something like:
SELECT homescore, awayscore FROM MatchData where matchdate = PredictionData.matchdate and hometeam=\"$reshometeam\" and awayteam=\"$resawayteam\" and homescore is not null";
I mean $res* can be the result of the compare function. But I dont have any idea how can I make that function.
I think I need to make an INSERT after calculate function.. I need suggestions.. Please
OK - I understand your problem a bit better ... but frankly, I still don't understand it well enough to give you a solution.
Suggestions:
1. If this *is* a homework assignment ... either do it yourself ... or at *least* cut/paste
*exactly* what your instructor told you to do. If there's a clearer "problem definition",
it would be extremely helpful to see it.
2. Treat the data access (e.g. the SQL query) and the points calculation as *two
separate problems*. Once you've got the solution, you might be able to combine
them (for example, do the query and the calculation in one really clever SQL
statement).
I would very strongly suggest:
a) Write a PHP function to compute the points (based on some
hard-coded dummy data)
b) Verify whether or not the solution is correct (to all possible predictions/scores)
c) Figure out the query to pass in the actual data (it looks like you've already
done this)
d) Optimize the solution (perhaps doing the bulk of the work in PHP, for example,
using arrays; or perhaps re-writing some/all of your PHP function in SQL).
Be advised, however, the mySQL can be *extremely* limited. My version, for example, doesn't even support sub-selects or ANSI-92 "join" syntax... So you'd probably find it easiest to do as much as you possible in PHP...
Distribution: Slackware 9.x, Knoppix, Damn Small Linux, RedHat.
Posts: 465
Original Poster
Rep:
Ok ... I made a SQL query
PHP Code:
SELECT PredictionData.lid FROM PredictionData LEFT JOIN MatchData ON PredictionData.matchdate = MatchData.matchdate WHERE PredictionData.homescore = MatchData.homescore AND PredictionData.awayscore = MatchData.awayscore;
Currently display a list of lid's of correct guessers. How can I give 3 points to the
lid's of correct guessers?
The question now is how can I INSERT or UPDATE into my Point's Table the point for each user..
My Point Table looks like;
PHP Code:
+-----+----------+--------+----------+--------+ | lid | username | Team | Division | Points | +-----+----------+--------+----------+--------+
You query each prediction, and the corresponding results.
You pass this into a function (either collectively, or a prediction at a time. It doesn't matter).
Then, for each prediction, your function computes a single value: the points (1..3).
You can do with this value whatever you like. It sounds like perhaps you want a third table - one to associate lid's with their accumulated points. If so, you'd do an INSERT into this hypothetical "contestant points" table.
But the key thing you need to figure out at this point is how to take ONE prediction, compare it with ONE game's results, and compute a SINGLE "points" value.
If a single contestant made one prediction for one game, then you've got one value.
If that same contestant made THREE predictions for that one game: well then, it's up to you how you want to handle it. You can keep the "winning value" and throw the other two way. You can average the three values. You can save all three predictions in your hypotehtical "contestant points" table and then give a prize to the individual who accumulated the most points over the entire season. It all depends on your preference.
'Hope that helps .. PSM
PS:
Sorry for razzing you about the homework thing ;-)!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.