2012-09-17 23 views
0

我我繼續我的插件開發的傳奇.. 所以我已經糾正了我在previuos代碼所做的所有的錯誤 - >Use of joomla methods stops file to work in plugin的Joomla插件阿賈克斯連接,DB錯誤

,現在我認爲我做的一切好,但分貝查詢不工作。我不知道這裏有什麼問題,數據庫查詢對我來說很好

<?php 
// Set flag that this is a parent file 
define('_JEXEC', 1); 

// No direct access. 
defined('_JEXEC') or die; 

define('DS', DIRECTORY_SEPARATOR); 

define('JPATH_BASE', dirname(__FILE__).DS.'..'.DS.'..'.DS.'..'.DS.'..'); 

require_once (JPATH_BASE .DS.'includes'.DS.'defines.php'); 
require_once (JPATH_BASE .DS.'includes'.DS.'framework.php'); 
jimport('joomla.database.database'); 


$db = JFactory::getDbo(); 

if(JRequest::getInt('id')) 
{ 

$id = JRequest::getInt('id'); 
$name = JRequest::getVar('name'); 

$query = "update #__messages set $name=$name+1 where id='$id'"; 
$db->setQuery($query); 
$db->query($query) or die('blogai'); 


?> 
<div style="margin-bottom:10px"> 
<b>Ratings for this blog</b> (<?php echo $total; ?> total) 
</div> 
<table width="700px"> 

<tr> 
<td width="30px"></td> 
<td width="60px"><?php echo $up_value; ?></td> 
<td width="600px"><div id="greebar" style="width:<?php echo $up_per; ?>%"></div></td> 
</tr> 

<tr> 
<td width="30px"></td> 
<td width="60px"><?php echo $down_value; ?></td> 
<td width="600px"><div id="redbar" style="width:<?php echo $down_per; ?>%"></div></td> 
</tr> 

</table> 

<?php 

} 
+0

工作是什麼讓你認爲數據庫查詢不工作?你是否收到任何錯誤消息。嘗試在$ db-> query($ query)之後打印$ db以獲得有關該問題的更多詳細信息。 – Anand

+0

我得到輸出(或死)「博客」輸出。我在哪裏必須把該打印$ db代碼。它後查詢它不會工作,我認爲是因爲輸出「博客」 – Jonuux

回答

0

嘗試this..its我

define('_JEXEC', 1); 
chdir("../../"); 
getcwd(); 
define('JPATH_BASE', getcwd()); 

define('DS', DIRECTORY_SEPARATOR); 

require_once (JPATH_BASE .DS.'includes'.DS.'defines.php'); 
require_once (JPATH_BASE .DS.'includes'.DS.'framework.php'); 

global $mainframe; 

$mainframe =& JFactory::getApplication('site'); 
$mainframe->initialise(); 

$db   = JFactory::getDBO(); 
+0

nop,這沒有鍛鍊。得到內部服務器錯誤 – Jonuux

+0

在文件'define('JPATH_BASE',dirname(__ FILE __)。DS''''。DS。'..'。DS。'..'。DS。'..' );'..看起來這是問題...給正確的DS計數.... – rynhe

+0

你可以發佈你的文件夾路徑? – rynhe