• I hope this is the right forum I’m asking this ..

    Anyway I want to add a custom page to wordpress (successful via template etc.)

    On this page I want to display content from a mysql table that is NOT part of the entire wordpress family (not a wp_ table)

    I can connect to the database and get the content I want. However all dynamic wordpress content in the sidebar (which comes after the mysql query I made) disappears.. I tried NOT using the close connection call but it’s still dead.

    Anybody have an idea what’s wrong here?

Viewing 7 replies - 1 through 7 (of 7 total)
  • sppadbase

    (@sppadbase)

    same issue.
    I am wndering if it is due to a loss of connection to the wp database.

    Thread Starter bpoulsendk

    (@bpoulsendk)

    I don’t know what causes it, but when I just created the tables in the same database as wordpress itself the problem disappeared.

    tugbucket

    (@tugbucket)

    You need to make a new call to wpdb:
    https://codex.www.ads-software.com/Class_Reference/wpdb

    <?php
    /* Config Values - You need to know these */
    $db_host = '';
    $db_user = '';
    $db_pass = '';
    $db_name = '';
    
    /* Connect to the new database */
    $externalQuery = new wpdb($db_user, $db_pass, $db_name, $db_host);
    
    /* Call WP's "get_results" on your query and create the array */
    $newQuery = $externalQuery->get_results("SELECT prodID, prodTitle, prodFormat, prodBinding FROM dvds ORDER BY prodID ASC") or die(mysql_error());
    
    //print_r($newQuery);
    
    /* Run a loop as usual on your array */
    foreach($newQuery as $q){
    	echo $q->prodTitle.'<br>';
    }
    ?>

    Granted my SELECT statement uses values in my test database. You can change those to suit.

    thanks! it works!!

    Can you include just the wpdb file from a separate standalone PHP application? or does it assume other vars exist?

    So far, so good. I just tried it, and it was just missing WP_DEBG so I defined it

    [65 lines of code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    Please let me know if the above approach will have missing parts that will cause me problems…

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Using custom mysql table inside wordpress page’ is closed to new replies.