Support » Fixing WordPress » wpdb question moving data then deleting

  • So I have this in a function and I cannot see why it isnt working, any clues please? It doesnt write to the archive table or delete from the original table

    if (isset($_POST['cleanold'])) {
        $cleanup = $wpdb->get_results(&quot;select * from wp_applications where Available_To < $date&quot;, ARRAY_A);
        $table_name = $wpdb->prefix . &quot;wp_applications_archive&quot;;
        foreach ($cleanup as $roww){
            $roww_id = $roww->id;
            $archive_success = $wpdb->query(&quot;INSERT INTO wp_applications_archive SELECT * FROM wp_applications where id= $roww_id&quot;);
        }
        if($archive_success){
            echo(&quot;Done&quot;);
        }else{
            echo(&quot;Nothing happened&quot;);
        }
        $result = $wpdp->get_results(&quot;SELECT * FROM wp_applications where Available_To < $date&quot;, ARRAY_A);
        foreach($result as $row){
            $row_id = $row->id;
            $wpdb->delete(wp_applications, array('id'=>$row_id));
        }
    }
Viewing 1 replies (of 1 total)
  • Dion

    (@diondesigns)

    First, all your double-quote characters are the &quot; entity, which would cause numerous PHP errors.

    Second, in your foreach() loops, you are referencing a row variable as an object, but you requested the result set to be an associative array.

Viewing 1 replies (of 1 total)
  • The topic ‘wpdb question moving data then deleting’ is closed to new replies.