• I am seeking advice regarding displaying database content in WORDPRESS. Ideally, I like to do similar way as WORDPRESS displays “Pages” and “Plugins” in the control panel.

    1. these tables contains a variable number of rows;
    2. assume each record has a “name”, I like what WORDPRESS does:
    2.1. when the record name is clicked, the row can expand or show a pop-up window to display more content of the data record
    2.2. when the cursor hovers above the record name, functions applicable to this record is displayed (this may need some coding, got it)

    Is such a functionality already available in WORDPRESS core, or is it available from plugins?

    Thanks for your advice

    John

Viewing 4 replies - 1 through 4 (of 4 total)
  • This process is simple, I think an example would make you understand it more, go to PHPMYADMIN, create a table named ‘my_table’, with 2 rows of ‘name’ and ‘bio’, and then, make some inserts, then use this code to retrieve data from that table:

    global $wpdb;
    $table = $wpdb->prefix . "my_table";
    $data = $wpdb->get_results( "SELECT * FROM $table");
    $count = count($data);
    if ( $count <= 0 )
        echo "No records available";
    if ( ! isset( $_GET["id"] ) ) {
        echo "<ul>";
        foreach ( $data as $key ) {
            $id = $key->id;
            $name = $key->name;
            echo "<li><a href=\"?id=$id\">$name</a></li>";
        }
        echo "</ul>";
    } else {
        $id = $_GET["id"];
        $data = $wpdb->get_results( "SELECT * FROM $table WHERE id = '$id' LIMIT 1");
        $count = count($data);
        foreach ( $data as $key ) {
            $name = $key->name;
            $bio = $key->bio;
            echo "Name: <strong>$name</strong>";
            echo "<p>Bio: <br> $bio</p>";
        }
        if ( $count <= 0 )
            echo "Nothing found for id-$id";
    }

    Just take your time, if it worked for you then start adding your custom rows and info, and I am not going to discuss how to make inserts because it isn’t the subject here..

    when the record name is clicked, the row can expand or show a pop-up window to display more content of the data record

    You could create hidden content, and display it onclick with JavaScript..

    Thread Starter zhuzh1

    (@zhuzh1)

    Samuel, thanks for your response, which takes care of the data retrieval. How to display the table, in the style of WORDPRESS admin console with the functionalities described in my original post?

    Thanks again

    If you want to benefit from admin CSS then, add those classes to table:

    <table class="wp-list-table widefat striped">
      <!--<tr><td>...</td></tr>--><
    </table>

    And as for the contents inside, you have to be more specific.

    Sorry.

    Thread Starter zhuzh1

    (@zhuzh1)

    Thanks for the direction of wp-list-table. It helps a lot. Seems to me that wp-list-table is what I am looking for. I also found this article very informative and useful.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Creating (dynamic) tables as WORDPRESS displays "Pages" or "Plugins"’ is closed to new replies.