Copy data into table / multidimensional array
-
Hello again,
Scenery: I want to copy data from “wp_users” to another table “user”.
SQL
INSERT INTO user(wpUserId, email) SELECT ID, user_email FROM {$wpdb->users} GROUP BY ID;
woulde be sooo easy. So it’s software development and it’s never “easy” and wpdb has query and insert.query combined with prepare reports an error, it’s about quoting.
$results = $wpdb->get_results( $wpdb->prepare( " INSERT INTO %s ( 'wpUserId', 'email' ) SELECT ID, user_email FROM {$wpdb->users} GROUP BY ID; ", $tabname ) );For the insert I have to split the sql up. So started to get the info
$results = $wpdb->get_results( " SELECT ID as wpUserId, user_email as email FROM {$wpdb->users} GROUP BY ID; ", ARRAY_A );which results in
Array ( [0] => Array ( [wpUserId] => 1 [email] => test@mail.com ) [1] => Array ( [wpUserId] => 2 [email] => anothertest@mail.com ) )How to transform that in a key => value array for the insert?
Or is there an easier way which I overlooked?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘Copy data into table / multidimensional array’ is closed to new replies.