我通过在论坛中查询特定论坛板的最新视频列表并将其显示在 Wordpress 主页上,将 SMF“集成”到了 Wordpress 中。但是,当我添加 ORDER BY 子句时,查询(我在同一页面的其他部分成功测试过)会中断。
为了添加到混合中,我使用自动嵌入插件来允许视频在主页上播放,并使用 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);
}
最佳答案
$sql = SELECT
我认为您缺少一个开头双引号。
关于php - mySQL ORDER BY ASC 有效,DESC 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2786047/