【发布时间】:2010-05-07 03:39:57
【问题描述】:
我已将 SMF “集成”到 Wordpress 中,方法是在论坛中查询来自特定论坛版块的最新视频列表并将它们显示在 Wordpress 主页上。但是,当我添加 ORDER BY 子句时,查询(我在同一页面的其他部分成功测试)中断了。
添加到组合中,我使用 Auto Embed 插件来允许在主页上播放视频,以及使用 jCarousel 功能来旋转它们。上次人们很友好地帮助我使用正则表达式过滤视频网址,我希望这次也能同样好运!
这是整个函数(去掉 DESC 就可以了……):
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);
}
【问题讨论】:
-
查询没有返回任何内容(null?),$vids 为空。
标签: php mysql wordpress sql-order-by