WordPress.org

Forums

Query from non-wp database (8 posts)

  1. Joe Hesse
    Member
    Posted 1 year ago #

    I have another database on my server besides the wordpress one.

    I want to do a query on a table in this database and have the result of the query appear in a wordpress page.

    I know MySQL and can pick up the necessary PHP.

    Please point me to some documentation that will help me. I just have to see some examples and will be able to figure it out. Perhaps something like how to write PHP code to create a wordpress page

    Thank you,
    Joe Hesse

  2. bcworkz
    Member
    Posted 1 year ago #

    Try W3 Schools? There's always the PHP Manual.

    You can actually place all the code on a custom page template, but to stay neat and organized, break up the code into discrete functions. Just make function calls on the page template and have the function definitions elsewhere, such as a class definition.

    Speaking of classes, you could use the wpdb class to make a new object similar to the global $wpdb object except it's connected to your other database.

  3. Joe Hesse
    Member
    Posted 1 year ago #

    I took the file page.php, copied it and called the copy Joe.php
    I put Joe.php in the correct folder for the theme I am using.

    It works great! The table is correct and styled the way I want.
    The only problem is that the width of the table is too small and it causes text in cells to wrap around.
    I want the width of the table to be nearly the full horizontal length of the screen. Putting the following in the <style> tags below didn't work:
    body {width:100%;}

    I know how to write CSS, I just don't know where to look. I could put my HTML code in a <div class = "Joe">
    and write CSS to make the screen width almost 100%. Where is the .css file that I should do this in?

    FYI: I am using the "Fruitful" theme.

    Thank you,
    Joe Hesse

    --------- Start of file Joe.php
    <?php
    /*
    Template Name: Joe
    */
    ?>

    <?php
    get_header();
    ?>

    <!DOCTYPE html>
    <html>

    <head>
    <style type="text/css">
    CSS Code to style a table is here.
    </style>
    </head>

    <body>

    <?php
    PHP code to do a SELECT, create an HTML table is here.
    ?>

    </body>
    </html>

    <?
    php get_footer();
    ?>
    ----------- End of file Joe.php

  4. bcworkz
    Member
    Posted 1 year ago #

    I think the problem is, in your theme, the container for your template is not 100%. Investigate with your browser's CSS analyzer. (Firebug plugin if using FF) It's simple enough to find the constricting container this way, but enlarging it can mess up the layout of the rest of your site. In such a case you may need to resort to dynamic CSS where script detects this template in use and outputs overriding style rules.

    On the chance you do not need dynamic CSS, the best way to override your theme's CSS is to create a child theme. This protects your customizations from theme updates. It may seem overkill for a couple CSS rules, but you'll probably find it useful in the future for other customizations.

    The child theme will also be useful if you need to resort to dynamic CSS. Implementing this is a bit tricky and not intuitive. There's a topic in these forums describing it in detail. It involves enqueuing a script referencing admin-ajax.php and passing the action as an URL parameter. The fake AJAX handler simply requires a PHP file that outputs CSS file contents. Hopefully you can find the topic with example code if you need it.

    BTW, take a look at your theme's header and footer files, you do not need to output some of the HTML that you are using, such as DOCTYPE, html, and head tags. Probably not even body.

  5. Joe Hesse
    Member
    Posted 1 year ago #

    I tried the following.

    I created a child theme to the "fruitful" theme.

    I modified my custom page template to enclose everything in the <body> with <div> tags. It looks like:

    <body>
    <div class="Schedule">
    PHP code to display table is here.
    </div>
    </body>

    My style.css for the child theme is:

    -----------------------------------
    /*
    Theme Name: fruitful-child
    Template: fruitful
    */

    @import url(../fruitful/style.css);

    body.Schedule { width:100%; } /* <== I added this */
    -----------------------------------

    Unfortunately, this did not work, it looks as before, the table needs to be bigger horizontally so the text in the cells don't wrap.

    Before I start learning about dynamic CSS please let me know that I have done everything right with the child theme.

  6. respectyoda
    Member
    Posted 1 year ago #

    First of all, you can just say...

    .Schedule{
       /* Your styling goes here */
    }

    Secondly, can you post your URL so I can take a look?

  7. Joe Hesse
    Member
    Posted 1 year ago #

    My web/blog is at "hallavenue.com" or "www.hallavenue.com" (no quotes).

    Please press the menu button on the top right labeled "Schedule".

    The table that appears is being read from my database and looks great except that the width should be a bit bigger so there is less wraparound in the table cells.

  8. Joe Hesse
    Member
    Posted 1 year ago #

    My site is down. I'm trying different themes.

Topic Closed

This topic has been closed to new replies.

About this Topic