• Resolved Andrew Leonard

    (@andrewleonard)


    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 TobiasBg

    (@tobiasbg)

    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

    (@andrewleonard)

    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 TobiasBg

    (@tobiasbg)

    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

    (@andrewleonard)

    Thanks
    You are better at this than I am

    Plugin Author TobiasBg

    (@tobiasbg)

    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.