How to split data and insert in different columns using WP DataTables [closed]

Question

I’ve just asked this question in StackOverflow (https://stackoverflow.com/questions/60888909/how-to-split-data-and-insert-in-different-columns-using-wp-datatables) but I think it might be more suitable here.

Im building a wordpress website that uses a form (using GravityForm plug in) and inserts into a table (WP DataTables plugin). The form takes information to place an order for groceries.

The way I currently insert the values of the field is by doing the following in my php file.

 $wpdb->insert( $table, array(
        'datecreated'           => date( 'Y-m-d' ),
        'name'                  => $entry[34],
        'productselected        =>$entry[36],
));

Where the entry number is the field ID number in the form.

This works fine.

I have the “product selected” as a radio button, and I want it to have a value also for the price, so the name and it’s value are inserted into the database in separate columns. For example, “eggs” will have a value of 3 and “milk” to have a value of 5. Then my data table will have “eggs” in the “product selected” column and “3” in the “productvalue” column. Image to show radio button with name and value

At the minute, it only passes in the value, and wrongly in the “productselected” column. I need the name to in the “productselected” column and “productvalue” to have the value of the whatever the selection was, in this case 3.

I believe I need to use regex to split this out and insert, something like this

 $wpdb->insert( $table, array(
        'datecreated'               => date( 'Y-m-d' ),
        'name'                      => $entry[34],
        'productselected'           =>$entry[36].name,
        'productvalue'              =>$entry[36].value

But not sure what the correct syntax would be

Any help appreciated as Ive searched the internet and spent days on this.

Thanks in advance

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/how-to-split-data-and-insert-in-different-columns-using-wp-datatables-closed/">

How to split data and insert in different columns using WP DataTables [closed]</a>
0
, Chillin' 2 months 0 Answers 63 views 0

Leave an answer