Title: access table data in php program
Last modified: July 18, 2020

---

# access table data in php program

 *  Resolved [Andrew Leonard](https://wordpress.org/support/users/andrewleonard/)
 * (@andrewleonard)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/access-table-data-in-php-program/)
 * Is it possible to access the table data in a php program?
    I want to be able 
   to say if table-id-nn if row-1 =”some text” do something
 * I don’t want to modify the table data or even display it

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/access-table-data-in-php-program/#post-13140312)
 * Hi,
 * thanks for your post, and sorry for the trouble.
 * You could use the TablePress PHP functions from the “table model” here, like
 *     ```
       $table_id = '123';
       $table = TablePress::model_table->load( $table_id, true, false );
       if ( 'some-text' === $table[0][0] ) {
         // do something.
       }
       ```
   
 * Regards,
    Tobias
 *  Thread Starter [Andrew Leonard](https://wordpress.org/support/users/andrewleonard/)
 * (@andrewleonard)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/access-table-data-in-php-program/#post-13142198)
 * Thanks
    There was a `$` missing from `model_table` and then this returns an array
   with a 2 dimensional array in one of the primary array elements so my code is
 *     ```
           $table_id = '27';
            $table = TablePress::$model_table->load( $table_id, true, false );
            foreach($table as $key => $value)
               {
               if ($key=='data')
                   {
                   foreach($value as $key => $value2)
                       {
                       foreach($value2 as $key => $value3)
                           {
                           if ($key=='0')
                               {
                               $l=strlen($title);
                               $k=substr($value3,0,$l);
                               if ($title==$k)
                                   {
                                   echo 'title= ',$title,' long_title= ', $value3;
                                   continue;
                                   }
                                }
                            }
                        }
                    }
               }
       ```
   
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/access-table-data-in-php-program/#post-13142450)
 * Hi,
 * ah, my bad for that typo! Good to hear that this was useful!
 * You might even be able to shorten all this to
 *     ```
       $table_id = '27';
       $table = TablePress::$model_table->load( $table_id, true, false );
       foreach( $table['data'] as $row ) {
           $first_cell_value = $row[0];
           $title_length = strlen( $title );
           $shortened_cell_value = substr( $first_cell_value, 0, $title_length );
           if ( $title === $shortened_cell_value ) {
               echo 'title= ', $title, ' long_title= ', $first_cell_value;
               break;
           }
       }
       ```
   
 * Best wishes,
    Tobias
 *  Thread Starter [Andrew Leonard](https://wordpress.org/support/users/andrewleonard/)
 * (@andrewleonard)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/access-table-data-in-php-program/#post-13142794)
 * Thanks
    You are better at this than I am
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/access-table-data-in-php-program/#post-13143912)
 * Hi,
 * no problem! Always happy to help!
 * Best wishes,
    Tobias

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘access table data in php program’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/access-table-data-in-php-program/#post-13143912)
 * Status: resolved