We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28121
    • 107 Posts
    In Revo, are there any best practices for taking information from my custom database table and displaying that information within a html table on a web page?

    I'm very new to PHP,mySQL,phpMyAdmin and have found a few php scripts online which I tried to use within a snippet.

    $connection = mysql_connect('localhost', 'my-username', 'mydbpassword'); //The Blank string is the password
    mysql_select_db('my-databasename');
    
    $query = "SELECT * FROM my-database-tablename"; //You don't need a ; like you do in SQL
    $result = mysql_query($query);
    
    echo "<table>"; // start a table tag in the HTML
    
    while($row = mysql_fetch_array($result)){   //Creates a loop to loop through results
    echo "<tr><td>" . $row['name'] . "</td><td>" . $row['age'] . "</td></tr>";  //$row['index'] the index here is a field name
    }
    
    echo "</table>"; //Close the table in HTML
    
    mysql_close(); //Make sure to close out the database connection




    I also wondered if I even needed to be specifying usernames and passwords in the first place as I'd assume my Revo resource already has permissions to connect with the database?

    Then I came across something caled PDO and XPDO and I think thats a bit advanced for me.

    If anyone can point me in the right direction, I'd be grateful.

      • 4172
      • 5,888 Posts
      you can use rowboat to display a list of custom-table-items, if you haven't a xpdo-db-schema:

      http://rtfm.modx.com/extras/revo/rowboat
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 28121
        • 107 Posts
        Thanks Bruno.
        Rowboat makes sense to me as it looks similar to other MODX Extras. Thanks for the pointer.

        On a happy note, I managed to get my original off-the-web PHP code working and quickly managed to create a simple dashboard with the following reports:

        - number of rows from custom table
        - number of rows from custom table with specific values

        Very excited to learn some more simple PHP scripts smiley


          • 3749
          • 24,544 Posts
          Here's another option that will allow you to use the MODX/xPDO methods to get the information: http://bobsguides.com/custom-db-tables.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 28121
            • 107 Posts
            Thanks Bob. A bit advanced for me right now :-(