-1

I have a WordPress site installed in a subfolder of my host and another php-based custom written CMS in the public_HTML. I'll like to fetch some data (a marquee text to be used on my WP theme header) from the php-based CMS to WordPress(note, the two sites have a different database). I already have a php code that fetch the data.

//test.php
<?php
include_once("admin/includes/config.php");
include_once("admin/includes/db.class.php");    
$db = new DB; $db -> open();
$strScrollingText = '';
$db -> query("select * from anouncements where status = 1 order by id desc");
if ($db -> rows() > 0)
  {
    $strScrollingText .= '<MARQUEE scrolldelay="100". direction="left">';
    while ($rs = $db -> rsset())
      $strScrollingText .= stripslashes($rs['anouncement']) . ', '; 
    $strScrollingText .= '</MARQUEE>';      
  }

When the test.php file above is placed in my public_html directory and previewed from my browser, it outputs a marquee text from the database. Then i moved the file into my themes folder (of course, I adjusted the two include file path in test.php by prefixing it with ../../../../) and tried to include the test.php using include('test.php'); in my theme's header.php, but when I refreshed my homepage, it was blank. I even copied the content of test.php into the and removed the 'echo $strScrolling text; ' and placed it where i want it to appear but still the homepage was still blank. I also used the #include directive in my Themes functions.php but this made my whole WordPress crash( I had to go and edit the file through cpanel to restore my wp). I don't know where i'm doing this wrong and it's really frustrating and I need any help I can get. I would even appreciate if i can get this done using a plugin. Thanks.

  • The <marquee> element is obsolete. – Nathan Johnson Mar 31 '18 at 18:05
  • a blank page is usually an indication of a php error. Enable WP_DEBUG, or look at your php error log files to find the exact cause – Mark Kaplun Mar 31 '18 at 18:28
  • Hello Nathan, I know it's obsolete and it's use should be discouraged(but I'm pretty sure that's not the problem) but right now, I just need the php calls to work first, then using CSS to create the marquee effect won't be a problem. – Mustapha Yusuff Mar 31 '18 at 22:36
  • Your question is very hard to read due to spelling errors alone. Also you are not showing the two includes. You need to show exactly as you have it aside from your actual credentials. As the others mention, enable WP_DEBUG and WP_DEBUG_LOG and there will be a debug.php under your wp_content – TurtleTread Mar 31 '18 at 23:03
  • Thanks for calling my attention to the spelling errors. They have been corrected. – Mustapha Yusuff Apr 1 '18 at 1:52
0

Thanks everyone, I have fixed the problem. The reason why there was an error was because the data was fetched as an object, not string. All I had to do is use WordPress Helpers instead. I used the $wpdb function to connect to the external database, then used the helper get_var() to fetch the text from database, then styled the output variable to give the marquee effect. Here is the complete code below.

<?php
//external_db_fetch.php
$mydb = new wpdb( 'username', 'password', 
'database_name', 'localhost' ); 

$stext = $mydb->get_var("SELECT col2 FROM 
table")
?>

Save the file above anywhere on your local host. Don't put it in header.php for security reasons. Just include it in your header with the right path include('path/to/external_db_fetch.php');

Then , encapsulate the output echo $stext; in a div class marquee to where you want the code to display(in your header).

Then edit (or create) the class marquee in your theme's stylesheet to give the desired styling. Thanks.

  • cool, please accept your own answer when you will be able to. – Mark Kaplun Apr 1 '18 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.