如何实现这段代码?

时间:2013-06-02 18:08:25

标签: php ajax

我不是PHP的专家。我想实现星级评分脚本。因此,我想在页面开头实施评级:

<?php require_once("ratings.php"; $rr = new RabidRatings(); ?>

然而,这给我一个服务器错误。

这是我打开HTML标记之前的PHP代码(在我希望阻止星级评分脚本的页面中):

<?
include "admin/configuration/config.php";
include "admin/configuration/main_class.php";

function en_string($str)
{
    return strtolower(str_replace(" ", "_", trim($str)));
}

function de_string($str)
{
    return str_replace("_", " ", trim($str));
}

;
$id = en_string($_GET['id']);
$id2 = en_string($_GET['id2']);
;

$path = "../";
if($id2)
{

    $sql = "SELECT * FROM fh_categories AS a JOIN fh_subcategories AS b ON a.fh_Cid=b.fh_Cid JOIN fh_software AS c ON b.fh_SCid=c.fh_SCid JOIN fh_version AS d ON d.fh_Sid=c.fh_Sid WHERE d.fh_Sid='$id' and d.fh_Vid='$id2' ";
    $path = "../../";
}
else
{
    $sql = "SELECT * FROM fh_categories AS a JOIN fh_subcategories AS b ON a.fh_Cid=b.fh_Cid JOIN fh_software AS c ON b.fh_SCid=c.fh_SCid JOIN fh_version AS d ON d.fh_Sid=c.fh_Sid WHERE d.fh_Vfront=1 and d.fh_Sid='$id'";
}

$query1 = mysql_query($sql);
$rec = mysql_fetch_array($query1);
$cid = $rec['fh_Cid'];
$scid = $rec['fh_SCid'];
$sid = $rec['fh_Sid'];
$description = $rec['fh_Sdescription'];
$technical = $rec['fh_Vtechnical'];
$changelog = $rec['fh_VchangeLog'];
$caption = $rec['fh_Sid'];
$company = $rec['fh_Scompany'];
$homepage = $rec['fh_Shomepage'];
$icon = $rec['fh_Sicon'];
$version = $rec['fh_Vcaption'];
$shot = $rec['fh_Vscreenshot'];
$size = $rec['fh_Vsize'];
$license = $rec['fh_Vlicense'];
$extension = $rec['fh_Vextension'];
$platform = $rec['fh_Vplatform'];
$did = $rec['fh_Did'];
$date = strftime("%d %b %Y", $rec['fh_Vdate']);
$language = "English";

$j = 1;
for($i = 0; $i < (strlen($shot)); $i++)
{
    if($shot[$i] != ';')
    {
        $screenshot[$j] .=$shot[$i];
    }
    else
    {
        $j++;
    }
}
?>

这是显示包含start的评级<div>的代码:

<?php $rr->showStars("anotherGreatArticle"); ?> 

当我将其添加到我的页面时,它不会在页面上显示任何内容,并且页面仅在中途加载。

我如何解决问题并使其有效?

2 个答案:

答案 0 :(得分:2)

语法错误:

<?php require_once("ratings.php"; $rr = new RabidRatings(); ?>

应该是

<?php require_once("ratings.php"); $rr = new RabidRatings(); ?>
//                              ^   forgot to close this

您忘了关闭require_once("ratings.php")

答案 1 :(得分:2)

你在require_once()之后忘了一个右大括号。

如果您使用具有语法和错误突出显示的编辑器/ IDE,则不会发生这种情况。任何体面的编辑都应该立即强调错误的代码。具有此类功能的免费编辑器是Notepad ++,Netbeans,Eclipse(从学习曲线中分类很容易 - 可以说是。)