使用joomla和k2我试图从我的数据库调用我的项目标题分配的类别,我使用此代码。为了实现这一点。但有些事情是错的。我确实得到了标题,但我没有得到类别名称。下面是我用来获取它的代码:
?php
$url= $_SERVER['REQUEST_URI'];
$data = parse_url($url);
$number = basename($data['path'], '.html');
$needle="-";
$number1=substr($number, 0, strpos($number, $needle));
?>
<?php
$db =& JFactory::getDBO();
$db->setQuery('SELECT title FROM #__k2_items WHERE id="'.$number1.'"');
$databaseTitle = $db->loadResult();
$db->setQuery('SELECT catid FROM #__k2_items WHERE id="'.$number1.'"');
$databaseCatid= $db->loadResult();
$db->setQuery('SELECT #__k2_categories.name FROM #__k2_categories INNER JOIN #__k2_items ON #__k2_categories.id = #__k2_items.catid WHERE #__k2_items.catid ="$databaseCatid" LIMIT 1');
$databaseNamecat= $db->loadResult();
?>
<h2>Submit a Charter Request for <?php echo $databaseTitle." from port ".$databaseNamecat; ?></h2>
答案 0 :(得分:0)
因为你在双引号之间包含一个变量。
试试这个
$db->setQuery("SELECT #__k2_categories.name FROM #__k2_categories INNER JOIN #__k2_items ON #__k2_categories.id = #__k2_items.catid WHERE #__k2_items.catid ='".$databaseCatid."' LIMIT 1 ");