• I am trying to insert in a wp table that has 17 columns. Does anyone have any thoughts on how to do this more efficiently? I’d like to incorporate wpdb->get_col_info(‘name’, offset) into this insert statement so I do not have to type them all out.

    Thoughts?

    $wpdb->query( $wpdb->prepare(“INSERT INTO $wpdb->mytable (column1, column2, column3, column4, column5, column6, column7, column8, etc etc)
    VALUES ( %d, %s, %s, %s, %s, %s, %s, %s, etc etc )”,
    $value1, $value1, $value1, $value1, $value1, $value1, $value1, $value1, etc etc) );

Viewing 2 replies - 1 through 2 (of 2 total)
  • This should go to the advanced section.

    Moderator bcworkz

    (@bcworkz)

    You can build a query string using a PHP loop, using some sort of structured data to feed the loop, either an array, file, whatever. You still have to type the data sooner or later unless the data can be generated dynamically with some sort of algorithm.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wordpress SQL INSERT Question’ is closed to new replies.