GravityForms Data Manipulation help needed - php

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

Related

Get next and previous records sorting by non-unique field

I was not able to find an answer while reading similar questions, so I'll ask my question here, appreciate any help on this matter.
In MySQL DB have a table with articles:
id date is_active title text
3 2017-01-20 1 New payment system goes live some articl
5 2017-01-21 1 Library v.2.5 released some articl
6 2017-01-22 1 New skins and themes some articl
7 2017-01-25 0 Terms and Conditions updated some articl
8 2017-01-26 1 Don't forget to subscribe some articl
10 2017-01-22 0 Support Chat beta release some articl
11 2017-01-30 1 Maintenance window next Sunday some articl
12 2017-01-28 1 Refer a friend and get a bonus some articl
13 2017-01-26 1 Follow us in social networks some articl
14 2017-01-22 1 Video sharing feature is now live some articl
I have 2 web pages:
a list of all active articles ordered by date (important: it is possible that several articles can have same date).
This works fine, no issue here.
single article read page, additionally I have "Next" and "Previous" links on that page
This is an issue.
I would like to show 'next' and 'prev' links as a href="article.php?id=8". So I would like to get next record ID from DB according to the query like this:
SELECT id FROM articles WHERE date > (SELECT date FROM news WHERE id = 6) and isactive = 1 ORDER BY date ASC LIMIT 1;
However my query does not work properly when it comes to defining next article id with the same date. When user stays on the article id=3 and clicks 'next' multiple times I would expect the following order of loading articles:
id title date is_active
5 Library v.2 2017-01-21 1
6 New skins a 2017-01-22 1
14 Video shari 2017-01-22 1
8 Don't forge 2017-01-26 1
13 Follow us i 2017-01-26 1
12 Refer a fri 2017-01-28 1
11 Maintenance 2017-01-30 1
But what I get is: 5, 6, 8, 12, 11. So 2 records are missing in this sequence (ids: 14 and 13) because they have same date.
I tried playing with different queries, but all results are not 100% right (in some cases it keeps returning same numbers, ex.: 5, 6, 14, 6, 14....., etc. )
Is is possible to get the 'next' IDs based on current ID and desired order via MySQL query(ies)? I am not against doing several queries or working with nested queries.
As a workaround, of course I can just retrieve an ordered array of all ids like this:
SELECT id FROM articles WHERE isactive=1 ORDER BY date
and then define 'next' and 'previous' using this array, however I don't like this solution.
If you can point me to some similar topics or other possible ways to solve this, please do.
Thank you.
SELECT id
FROM articles
WHERE date >= (SELECT date -- changed
FROM news
WHERE id = 6)
AND isactive = 1
AND id NOT IN(6) -- added, maybe id!=6 or id<>6
ORDER BY date ASC
LIMIT 1
-- (all id date >= date) - (id=6)
Why you do this, why not use
SELECT id FROM news ORDER BY date ASC LIMIT 6,1 -- possition, count
If SQL query caching, this is may be faster.

How count sum of field value and sort them as per userid using PHP and MySQL

I need some help. I need to calculate the sum of numeric field value as per userid and place them into array using MySQL and PHP. I am explaining my table below.
db_like:
id like userid
1 1 10
2 2 11
3 1 10
4 2 11
Here I need to count the sum of like field value as per userid and place the result into array. Please help.
SELECT SUM(`like`) AS `likes` FROM [table] GROUP BY `userid`;

Add on numbers in a table

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

MySQL - Updating and incrementing a column value, starting from 1, for a range of rows based on and sorted by another column

I have this table:
id track_name datetime weight
1 aName 2010-06-01 09:00:00 1
2 theName3 2010-07-01 11:00:00 2
3 heyThere 2010-08-01 16:00:00 3
4 abcd 2010-08-01 22:44:00 4
5 g123go 2010-08-01 22:00:50 5
6 foobar 2010-09-01 13:11:00 6
7 barfoo 2010-11-01 12:00:55 7
8 barbar 2010-12-01 11:11:00 8
The weight determines the row record order. It is used for ordering a playlist. And the user can move items up and down, thus reordering in the simple fashion, in which works great.
Now I wonder if there is possible to write a single query that can change the 'weight' value based on the 'date' column, ordering by either DESC or ASC. The same for the 'track_name' column.
Example pseudo query:
UPDATE table SET weight (start from 1) ORDER BY datetime ASC
My alternative is to fetch all rows and process each and everyone of them on the web server, which I doubt is the most effecient way, if there are thousands of records.
I don't think you can do it with a single query. You need a counter, this means you need a loop. If you want to do it with MySQL only, you can create a stored procedure. If not, just write a PHP script (witch might will be a bit slower). Logic is the same:
Get all the data from the table;
Loop through every record in the
order you need and update weight
parameter.
You could use a temporary table with an auto incremented id and select insert into it using your order.

PHP Mysql Poll exam inserting?

table question:
id question
1 myquestion1
2 myquestion2
3 myquestion3
4 myquestion4
5 myquestion5
table answer:
id qid userid answer
1 1 1 myanswer
2 2 1 myanswer
3 3 1 myanswer
4 4 1 myanswer
5 5 1 myanswer
My problem is how can i insert using php mysql for my answer after answering 5 questions?
any one has an idea?
sample question: After clicking radio button go to next question then after answering submit and insert answer into database..
Are you married?
Yes
No
Do you play basketball?
Yes
No
ect....
Any help very much appreciated!
Thank you!
array(
['question_id'] =>Yes //Are you married?
['question_id'] =>no //Do you play basketball?
)
You need to get this array by posting answer data

Categories