bpoulsendk
Member
Posted 5 months ago #
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?
sppadbase
Member
Posted 2 months ago #
same issue.
I am wndering if it is due to a loss of connection to the wp database.
bpoulsendk
Member
Posted 2 months ago #
I don't know what causes it, but when I just created the tables in the same database as wordpress itself the problem disappeared.
You need to make a new call to wpdb:
http://codex.wordpress.org/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.
sppadbase
Member
Posted 2 months ago #
tezza71
Member
Posted 2 months ago #
Can you include just the wpdb file from a separate standalone PHP application? or does it assume other vars exist?
tezza71
Member
Posted 2 months ago #
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]
tezza71
Member
Posted 2 months ago #
Please let me know if the above approach will have missing parts that will cause me problems...