WordPress.org

Ready to get started?Download WordPress

Forums

dbview
PHP snippet to a list of record in multidimensional array (5 posts)

  1. lhl
    Member
    Posted 1 year ago #

    Hi John,

    Thank you for your effort in developed such a great plugin.
    We find your plugin very useful, but we are facing problem when try to filter some data from a multidimensional array where we believe these data are unserialized data.

    We have a column named 'Data' with the following multidimensional array as its record:
    Array
    (
    [Griffin] => Array
    (
    [0] => Peter
    [1] => Lois
    [2] => Megan
    )
    [Quagmire] => Array
    (
    [0] => Glenn
    )
    [Brown] => Array
    (
    [0] => Cleveland
    [1] => Loretta
    [2] => Junior
    )
    )

    We want to show a set of value where the element in the sub-array is 2.

    Kindly assist.

    Thank you.

    http://wordpress.org/extend/plugins/dbview/

  2. john ackers
    Member
    Plugin Author

    Posted 1 year ago #

    Ok. I understand the problem. Will get back to you tomorrow. I think we need to have a row level php snippet. It would be easy to add the functionality but it needs to be simple to use.

  3. john ackers
    Member
    Plugin Author

    Posted 1 year ago #

    Do you want to filter particular records? It's not possible to filter records using anything other than the SQL where clause.

    But if you just want to show a particular field, the snippet is
    `return $value[$xyz][2];
    where $xyz is 'Griffin' or 'Brown'.

    Do you want to represent your record above as 1 row or as 3 rows? Can you show me what result you are looking for?

  4. lhl
    Member
    Posted 1 year ago #

    Hi John,

    We want to show the following values as result:
    Megan
    Junior

    I'm using:return $value[$Griffin][2];
    but i cann't get what i want.

    Instead, i received the following warning:
    Warning: Illegal string offset 'data' in ...\wp-content\plugins\dbview\DBViewTable.class.php(153) : runtime-created function on line 1
    {"success":true,"messages":["Note: this query has not been saved.<\/span>","1 rows found.<\/span>"],"updates":[{"selector":".dbview","html":"

    project 1<\/h2>\r\n\r\n
    1 item<\/span><\/th><\/tr>
    data<\/th><\/tr>
    return $value[$Griffin][2];<\/th><\/tr><\/thead>\r\n
    :<\/td><\/tr><\/tbody>\r\n<\/table style='width:98%'>"}],"_ajax_nonce":"86a4ef1147"}

    Kindly assist.

    Thank you.

  5. john ackers
    Member
    Plugin Author

    Posted 1 year ago #

    If you create a table using

    create table familyguy (tree varchar(300));
    insert table familyguy values('a:3:{s:7:"Griffin";a:3:{i:0;s:5:"Peter";i:1;s:4:"Lois";i:2;s:5:"Megan";}s:8:"Quagmire";a:1:{i:0;s:5:"Glenn";}s:5:"Brown";a:3:{i:0;s:9:"Cleveland";i:1;s:7:"Loretta";i:2;s:6:"Junior";}}');

    then using
    select tree, tree as tree1 from familyguy
    with the PHP snippet

    $o = unserialize($value);
    $res = array();
    if (is_array($o))
      foreach($o as $v)
      {
        $res[] = $v[2] ;
      } ;
    return implode("<br/>", $res);

    You get in one cell in a table

    Megan

    Junior

    Are we closer?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.