Joomla插件数据库错误?这有什么不对?

时间:2012-08-23 07:47:17

标签: ajax plugins joomla

我刚刚开始学习Jplugin开发,所以在这里我做了一个小小的投票脚本。这里的一切工作正常,但我希望conf.php文件以joomla框架样式制作。如您所见,1和2文件完美结合。我想使用第三个例子而不是第二个例子,其中我使用简单的PHP代码。我试图做的最后一个例子是使用joomla框架,但它不起作用。我不知道该代码有什么问题。任何人都可以看出我在哪里犯了错误,或者可能远远没有做错了?

<?php
defined( '_JEXEC' ) or die;
?>

<?php
class plgSystemRatingx extends JPlugin

{
   public function onContentBeforeDisplay()
   {
?>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".like").click(function()
{
var id=$(this).attr("id");
var name=$(this).attr("name");
var dataString = 'id='+ id + '&name='+ name;
$("#votebox").slideDown("slow");

$("#flash").fadeIn("slow");

$.ajax
({
type: "POST",
url: "conf.php",
data: dataString,
cache: false,
success: function(html)
{
$("#flash").fadeOut("slow");
$("#content").html(html);
} 
});
});

$(".close").click(function()
{
$("#votebox").slideUp("slow");
});

});
</script>
<body>
<div style="margin:50px">
<a href="#" class="like" id="1" name="up">Like</a> -- <a href="#" class="like" id="1" name="down">Dislike</a>
<div id="votebox">
<span id='close'><a href="#" class="close" title="Close This">X</a></span>
<div style="height:13px">
<div id="flash">Loading........</div>
</div>
<div id="content">
</div>
</div>
</div>
<?php
      return true;
   }
}

这段代码完美无缺

<?php
$mysql_hostname = "localhost";
$mysql_user = "px";
$mysql_password = "px";
$mysql_database = "jum";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) 
or die("Opps some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");


if($_POST['id'])
{
$id=mysql_real_escape_string($_POST['id']);
$name=mysql_real_escape_string($_POST['name']);


mysql_query("update messages set $name=$name+1 where id='$id'");


$result=mysql_query("select up,down from messages where id='$id'");
$row=mysql_fetch_array($result);
$up_value=$row['up'];
$down_value=$row['down'];
$total=$up_value+$down_value;

$up_per=($up_value*100)/$total;
$down_per=($down_value*100)/$total;
?>
<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

}
?>

这种以joomla风格制作的东西根本不起作用

<?php
defined( '_JEXEC' ) or die;
?>
<?php
if(JRequest::getVar('id'))
{

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

$db = JFactory::getDbo();

$query = $db->getQuery(true);
$query2 = $db->getQuery(true);
$queryup = $db->getQuery(true);
$querydown = $db->getQuery(true);

$query->update('messages');
$query->set("message = 1");
$query->where("id = $id");

$query2->select('up,down');
$query2->from('messages');
$query2->where("id = $id");



$queryup->select('up');
$queryup->from('messages');
$queryup->where("id = $id");

$querydown->select('down');
$querydown->from('messages');
$querydown->where("id = $id");


$db->setQuery( $query );
$db->query();
$db->setQuery( $query2 );
$db->query();

$db->setQuery( $queryup );
$data0 = $db->query();
$db->setQuery( $querydown );
$data1 = $db->query();


$up_value= $db->insertid($data0);;
$down_value = $db->insertid($data1);

$total=$up_value+$down_value;

$up_per=($up_value*100)/$total;
$down_per=($down_value*100)/$total;

?>

<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
}

1 个答案:

答案 0 :(得分:0)

试试这个 $ query-&gt; where('id ='。$ db-&gt; qn($ id));