Say i have a database with a table which i have numbers on. Is there some way that i can add 1 number digit onto another one. for example i query what the fist number is and then add 1 number on to that. like if it was 1 and i clicked a button it will make it 2. How would this be possible? At the moment i just add a 1 into a new row every time but i need it to be classified under names. and it is really easy the way i have it now. if you don't understand don't hesitate to comment.
mine. it adds up all the ones
1
1
1
1
1
what i need to accomplish.
joe frank 1
and when i click the link
joe frank 2
Does that make sense
Related
I've been struggling on the following (algorithmic?) problem for days now. I have a list of persons that I need to group evenly. Each "round" of groupings is stored so that the next time (round) I try to group people together, we group them if they were not matched together during a previous round.
Example:
John
Bob
Laura
Lucy
Michael
Mark
1st round
Group 1
John
Bob
Laura
Group 2
Lucy
Michael
Mark
Now for the 2nd round we have to avoid grouping John Bob Laura together (or at least minimize it).
I came up with the solution that works for these small edge cases where I create a pairing matrix with
[John - Bob] = 1 (number of times they got paired together in previous rounds)
[Bob - Laura] = 1
etc...
I then loop through that matrix, for each person I find the lowest number of times that person got paired with someone else and add these 2 to the list. Etc, until everybody got added to that list.
I then split that list into groups of desired number (the group size is the only parameter).
I found out that this doesn't work after a few rounds or with larger "rosters".
I'm getting close to think that this might be a NP problem because I'd have to iterate many many times to find the perfect "list".
Is there an algorithm I should look into? I'm coding this in PHP but Java or pseudo code works too.
A roster containing 36 persons.
1st round, group size = 6
2nd round, group size = 4
I should not have someone paired with someone else more than once.
With my solution, I have around 10 pairings that happened twice.
I have searched all over the internet and I have had no luck in finding the answer to my question. I hope this has not specifically been posted yet, but if you can point to where i can find the answer I would appreciate it.
I have set up a site that I am building into a fantasy golf site. I am using GravityForms as my form plugin. I have all the other features I want set, set up and need help with this last thing.
id lead_id form_id field_number value
1 1 1 1 Hosker
2 1 1 7 b**********#yahoo.com
3 1 1 6 Hyundai Tournament of Champions
4 1 1 3 Adam Scott
5 1 1 4 Harris English
6 1 1 5 2014-01-02 23:59:47
7 1 1 8 5b409692-e9ed-486e-8d77-7d734f1e023d
This is what my form submission gets posted as in the database. I would like to be able to take all of the data from this form and do an sql query and put it all in one row. Is that possible? The two columns that I will need to build my query around would be from lead_id and value where the value that I will be basing the query on is in row 7. The only value that I will know is in row 7. Thanks in advance for your help.
This is the result I am looking for
id lead_id form_id field_number value value value value value value value
1 1 1 1 Hosker b**********#yahoo.com Hyundai Tournament of Champions Adam Scott Harris English 2014-01-02 23:59:47 5b409692-e9ed-486e-8d77-7d734f1e023d
I would hook into the gravityform submission action and then perform whatever logic is required at that point to do the insert into the database.
add_action("gform_after_submission", "on_gform_submit");
Then create a function to accept the entry as an argument.
function on_gform_submit($entry){
}
Inside of this function $entry is an array that has the ID of each field (as per the back end) as the key. So if for instance message had an ID of 10, then it would be
$message = $entry['10'];
Then when you're done, simply input the data using a standard SQL Insert statement
I have a question with im really unsure with.
First feel free to downvote me if its a must but i would really like to hear a more experienced developers opinion.
I am building a site where i would like to build similar functionality like google circles.
My logic would be this.
Every user will have circles attaced to them after signup.
example if the user will sign up
form filed and the following querys will be insierted to the database
**id | circle_name | user_id**
------------------------------------
1 | circle one | 1
------------------------------
2 | circle two | 1
------------------------------
3 | circle three | 1
Every circle will have a primary key
But this is what im unsure with, so after a time im a bit scared that the table will break, what im mean is if it will reach a number of id's it will actually stop generating more.
When you specifiy an int in the database the default value is 11, yes i know i can incrase or set it to the value what i want, but still giveing higher values is a good idea?
or is there any possibility to make a primary key auto increment to be unlimited?
thank you for the opinions and help outs
or is there any possibility to make a primary key auto increment to be unlimited?
You can use a BIGINT.
Strictly speaking it's not unlimited, but the range is so incredibly huge that you wouldn't be able to use up all the values even if you tried really hard.
Just run some maths and you ll get the answer yourself. If a length can store billions of values and you don't expect to have 1 million new registrations every week then getting to a point where it breaks would be "practically" tough, even if "theoretically" possible
I hope to create a list of matches of a soccer champion of every week,so I want to get a result with next and prev button,so something like that:
Next | week 3 | Prev
-------------------------
tream 1 1-0 team 2
The list of teams I get it from another php page "content.php" and I used HTML "table" to make list
Finally I hope to get all content for every week from "content.php" and change it when I click next or previous buttons...
Ok,I found a great and simple solution here http://www.w3schools.com/php/php_ajax_database.asp
tnks.
Not sure of the best way to go about this?
I want to create a tournament bracket of 2,4,8,16,32, etc teams.
The winner of the first two will play winner of the next 2 etc.
All the way until there is a winner.
Like this
Can anyone help me?
OK so more information.
Initially I want to come up with a way to create the tournament with the 2,4,8,16,etc.
Then when I have all the users in place, if they are 16 players, there are 8 fixtures.
At this point I will send the fixture to the database.
When all the players that won are through to the next round, i would want another sql query again for the 2 winners that meet.
Can you understand what i mean?
I did something like this a few years ago. This was quite a while ago and I'm not sure I'd do it the same way (it doesn't really scale to double-elimintation or the like) How you output it might be a different question. I resorted to tables as it was in 2002-2003. There are certainly better techniques today.
The amount of rounds in the tournament is log2(players) + 1, as long as players is one of the numbers you specified above. Using this information you can calculate how many rounds there are. The last round contains the final winner.
I stored the player information something like this (tweek this for best practices)
Tournament
Name
Size
Players
Tournament
Name
Position (0 to tournament.size - 1)
Rounds
Tournament
Round
Position (max halves for each round)
Winner (player position)
Note in all my queries below, I don't include the "Tournament = [tournament]" to identify the tournament. They all need it.
It's rather simple to query this with one query and to split it out as needed for the different rounds. You could do something like this to get the next opponent (assuming there is one). For round 1, you'd simply need to get the next/previous player based on if it was even or odd:
SELECT * FROM Players WHERE Position = PlayerPosition + 1
SELECT * FROM Players WHERE Position = PlayerPosition - 1
For the next round, if the user's last Round.Position was even, you'll need to make suer that the next position up has a winner:
SELECT Player FROM Rounds WHERE Position = [playerRoundPosition] - 1
If not, the next player isn't decided, or there's a gap (don't allow gaps!)
If the users last Round.Position was odd, you'll need make sure there's a user below them AND that there's a winner below them, otherwise they should automatically be promoted to the next round (as there is no one to play)
SELECT COUNT(*) FROM Players WHERE Position > [Player.Position]
SELECT Player FROM Rounds WHERE Position = [playerRoundPosition] + 1
On a final note, I'm pretty sure you could use something like the following to reduce the queries you write by using something like:
SELECT Player FROM Rounds WHERE Position + Position % 2 = [playerRoundPosition]
SELECT Player FROM Rounds WHERE Position - Position % 2 = [playerRoundPosition]
Update:
Looking over my original post, I find that the Rounds table was a little ambigous. In reality, it should be named matches. A match is a competition between two players with a winner. The final table should look more like this (only the name changed):
Matches
Tournament
Round
Position (max halves for each round)
Winner (player position)
Hopefully that makes it a bit more clear. When the two players go up against each other (in a match), you store that information in this Matches table. This particular implementation depends on the position of the Match to know which players participated.
I started numbering the rounds at 1 because that was more clear in my implementation. You may choose 0 (or even do something completely different like go backwords), if you choose.
In the first round, match 1 means players 1 and 2 participated. In match 2, the players 3-4 participated. Essentially the first round is simply players position and position + 1 participated. You could also store this information in the rounds table if you need more access to it. Every time I used this data in the program, I needed all the round and player information anyways.
After the first round, you look at the last round of matches. In round 2, match 1, the winners from matches 1 and 2 participate. Round 2, match 2, the winners from match 3 and 4 participate. It should look pretty familiar, except that it uses the match table after round 1. I'm sure there's a more efficent way to do this repetitive task, I just never got enough time to refactor that code (it was refactored, just not that much).
Use arrays and remove the losing teams from the main array. (But keep 'em on a separate array, for reference and reuse purposes).