views:

185

answers:

4

I've "integrated" SMF into Wordpress by querying the forum for a list of the most recent videos from a specific forum board and displaying them on the Wordpress homepage. However when I add the ORDER BY clause, the query (which I tested on other parts of the same page successfully), breaks.

To add to the mix, I am using the Auto Embed plugin to allow the videos to be played on the homepage, as well as using a jCarousel feature to rotate them. People were kind enough to help me here last time with the regexp to filter the video urls, I'm hoping for the same luck this time!

Here is the entire function (remove the DESC and it works...):

function SMF_getRecentVids($limit=10){
global $smf_settingsphp_d;

if(file_exists($smf_settingsphp_d)) include($smf_settingsphp_d);

include "AutoEmbed-1.4/AutoEmbed.class.php";
$AE = new AutoEmbed();
$connect = new wpdb($db_user,$db_passwd,$db_name,$db_server);
$connect->query("SET NAMES 'UTF8'");

$sql = "SELECT m.subject, m.ID_MSG, m.body, m.ID_TOPIC, m.ID_BOARD, t.ID_FIRST_MSG
FROM {$db_prefix}messages AS m
LEFT JOIN {$db_prefix}topics AS t ON (m.ID_TOPIC = t.ID_TOPIC)
WHERE (m.ID_BOARD = 8)
ORDER BY t.ID_FIRST_MSG DESC";

$vids = $connect->get_results($sql);

$c = 0;
$content = "imageCarousel_itemList = [";
foreach ($vids as $vid) {
    if ($c > $limit) continue;
    //extract video code from body
    $input = $vid->body;
    $regexp = "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i";
    if(preg_match_all($regexp, $input, $matches)) { 
        $AE->parseUrl($matches[0][0]);
        $imageURL = $AE->getImageURL();
        $AE->setWidth(290);
        $AE->setHeight(240);            
        $content .= "{url: '".$AE->getEmbedCode()."', title: '".$vid->subject."', caption: '', description: ''},";                      
    }
    $c++;
}
$content .= "]";
echo $content;

$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);   

}

+1  A: 
$sql = SELECT

I think you're missing an opening double-quote.

Delan Azabani
My bad, I copied incorrectly, though I wish it was that simple.
Ben
A: 

Yes this may be your issue, use like this

$sql = "SELECT m.subject, m.ID_MSG, m.body, m.ID_TOPIC, m.ID_BOARD, t.ID_FIRST_MSG
FROM {$db_prefix}messages AS m
LEFT JOIN {$db_prefix}topics AS t ON (m.ID_TOPIC = t.ID_TOPIC)
WHERE (m.ID_BOARD = 8)
ORDER BY t.ID_FIRST_MSG DESC";
Karthik
A: 

Turns out it wasn't the query, it was the results. I didn't escape an apostrophe. Updated with an addslashes() to fix problem:

$content .= "{url: '".$AE->getEmbedCode()."', title: '".addslashes($vid->subject)."', caption: '', description: ''}";

Off to bed. Thanks for the quick responses!

Ben
Never ever assume a query executed properly. Always check to see if an error occured. Even if the SQL command is valid would normally execute, there may be other problems with the database. DBMS server may have died, be unreachable, or a previous query/transaction has locked the table and your query times out.
Marc B
A: 

to intergrate SMF into Wordpress there is a plugin that can help you do that it is called : WP-Forum

search for a plugin called WP-Forum and install from there.

Here is the website http://www.fahlstad.se and their sample forum http://www.fahlstad.se/wp-forum/

There is a little trick tho, after you install the plugin, go to your filezilla/file manager, browse to wp-content/plugins and rename wpforum to wp-forum , then enable the plugin, otherwise you will be getting an error message

hope that helps

mireille raad
Ben
Hope you will be to submit your updates to the original author :)and good luck !
mireille raad