Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Extrapage to display table with query options

I've imported a large csv with cardata in a mysql database. I would like to display this data on my forum on a custom page. I could add an extra page with the Extra Page plugin. What would be the recommended way to display the table on that page ? (I know sql and python but not php).


  • Options
    x00x00 MVP
    edited February 2016

    Use a pager module, since you said it has a lot of data. However how you display it is up to you.

    Python has a nicer syntax and has packages so it wins over PHP. However PHP is pretty decent all round too.

    As far as using the framework you could use a few thing. If it is in a different database if you want to use the query builder you need to create a new instance of the driver pointing to the database with he table prefix.

    It would be easier just to import the table into you current database with the same prefix. Not need to worry about that authentication. Then you can just use Gdn::sql() to build queries with.

    Sanitation have a look at Gdn_Format class.

    Alternatively if you like python and this is standalone resource. Just create a page, and put the table in an iframe, or some dynamically loaded javascript/jquery table library, with filters, etc.

    This might be easiest for you as you would just need to lean how to create pages, add you javascript and css resources and a small amount of markup. Then you can have you python endpoint for the data retrieval.

    grep is your friend.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    This might be a start but x00 has made some very good points in regards to the pager and the sanitizing!

    // If you haven't prefixed your tablename with 'GDN_' you should set
    // the prefix (temporarily for your query) to "".
    Gdn::database()->DatabasePrefix = '';
    // Get data from db.
    $result = Gdn::database()->sql()
      ->select('column_a, column_b, column_c')
      // For getting all columns you can use select('*') or even select()
      ->select('column_z', '', 'Column Z') // you can use select() more than once and use aliases
      ->where('column_b >=', 9)
    // Loop through results and throw out markup.
    echo '<table>';
    foreach($result as $row) {
        echo '<tr>';
        echo '<td>', $row->column_a, '</td>';
        echo '</tr>';
    echo '</table>';

    Search the source code for examples. It is well documented

  • Options

    If it is meant to be a resource. The simplest thing you can do is use one of the many JavaScript libraries on the web, typically JSON driven. Then you don't have to spend so much time on interface.

    If you want to use an vanilla based endpoint it must go through the dispatcher. I.e. controller and method. No arbitrary endpoints, or force loading. Or else you will have to schedule your electro-shock treatment appointment.

    If you make a standalone script it up to you to make it secure.

    grep is your friend.

Sign In or Register to comment.