Fehler in Vote Funktion

Ok hier das ganze Script ist aber nur der Teil wo die News gemacht werden
aber darum geht es ja letztendlich.

Ich habe den Abschnitt durch leere Zeilen davor und dahinter etwas herausgehoben.

PHP:
<?php

// Hier werden die normalen News kategoriebezogen selektiert und "makeNews" beauftragt


    function buildPages($total, $per_page, $shown_pages, $current_page, $LINK, $LINK_ADD) {

        if ($shown_pages < 200) {
            $shown_pages = 200;
        } elseif ($shown_pages % 2 == 0) {
            $shown_pages ++;
        }
        $LINK = str_replace("&amp;p=".$current_page, "", $LINK);
        if ($current_page === "") {
            $current_page = 1;
        }

        $page_num = (int)($total / $per_page);
        $page_num += ($total % $per_page) ? 1 : 0;
        $offset = $current_page - ($shown_pages - 1) / 2;
        if  ($offset > ($page_num - $shown_pages + 1)) {
            $offset = $page_num - $shown_pages + 1;
        }
        if ($offset < 1) {
            $offset = 1;
        }
        $output = ($page_num > 1) ? "\r\n$page_num seiten:" : "$page_num page:";
        $output .= ($offset > 1) ? "\r\n<a $LINK_ADD class=\"navi\" href=\"$LINK&amp;p=1\" title=\"erste\">&laquo;</a>" : "";
        $offset_end = ($shown_pages < $page_num) ? $offset + $shown_pages : $page_num + 1;
        for ($i = $offset; $i < $offset_end; $i++ ) {
             $output .= ($i != $current_page) ? "\r\n<a $LINK_ADD class=\"navi\" href=\"$LINK&amp;p=$i\">$i</a>" : "\r\n<b>$i</b>";
        }
        $output .= ($offset < ($page_num - $shown_pages + 1)) ? "\r\n<a $LINK_ADD class=\"navi\" href=\"$LINK&amp;p=$page_num\" title=\"letzte\">&raquo;</a>" : "";
        return "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"news\">
  <!--DWLayoutTable-->
  <tr>
    <td width=\"100%\" class=\"news\">$output</td>
  </tr></table>\r\n";
    }

    if (!function_exists("printNews")) {
    function printNews() {

        global $extension,
               $show,
               $cat,
               $catindex,
               $options,
	       $PHP_SELF, $QUERY_STRING, $p,
               $result;

        require("config.inc".$extension);

        $dbconn = new Coresql($db_server, $db_database, $db_account, $db_password);
        $p = ($p) ? $p : 1;
        if ($cat == 1 || $cat == 0) {
            $querypart = "";
        } elseif ($cat != "") {
            $category = $dbconn->fetchArray("SELECT * FROM $categorytable WHERE id = $cat");
            if ($category['internal'] != 1) {
                $querypart = " WHERE category = $cat";
            } else {
                $querypart = " WHERE category = 0";
            }
        }
        $newsdata  = $dbconn->fetchMultiple("SELECT * FROM $newstable$querypart ORDER BY sticky DESC, time DESC LIMIT ".($options[news_nr] * ($p -1)).",$options[news_nr]");
        $rows  = $dbconn->countRows("SELECT NULL FROM $newstable$querypart");
        $close = $dbconn->close();
        if ($newsdata != "") {
            foreach ($newsdata as $key=>$result) {
                $dbconn = new Coresql($db_server, $db_database, $db_account, $db_password);
                $catindex = $dbconn->fetchArray("SELECT * FROM $categorytable WHERE id = $result[category]");
                $close = $dbconn->close();
                if (($catindex['internal'] != 1) && ($result['is_confirmed'] == 1)) { makeNews(); }
            }
            $link = ($cat) ? $PHP_SELF.$QUERY_STRING."&amp;cat=".$cat : $PHP_SELF.$QUERY_STRING;
            print buildPages($rows, $options['news_nr'], 5, $p, $link, "");
        } else { print "<div class=\"news\" align=\"center\"><b>Keine News gefunden!</b></div>\r\n<br />\r\n"; }
    }}

// Hier werden einzelne Newspostings an "makeNews" geleitet

    if (!function_exists("printSingleNews")) {
    function printSingleNews() {

        global $extension,
               $newsdata,
               $styledata,
               $catindex,
               $result,
               $options,
               $comments,
               $news_id;
        require("config.inc".$extension);

        $dbconn = new Coresql($db_server, $db_database, $db_account, $db_password);
        $catindex = $dbconn->fetchArray("SELECT * FROM $categorytable WHERE id = $result[category]");
        $close = $dbconn->close();
        if (($catindex['internal'] != 1) && ($result['is_confirmed'] == 1)) { makeNews(); }
    }}

// Hier wird die Vorschau erstellt

    if (!function_exists("printPreview")) {
    function printPreview() {

        global $extension,
               $newsdata,
               $styledata,
               $catindex,
               $result,
               $debug,
               $options,
               $comments,
               $news_id;
        require("config.inc".$extension);
        require("corebb".$extension);
        if ($debug == "ON") { print "printPreview<br />\r\n"; }

        if ((isset($_POST['author_id'])) && (isset($_POST['news_text'])) && (isset($_POST['news_title']))) {
            $postvars = array('author_id' ,'news_title' ,'news_text' ,'icon_id', 'show_email', 'category', 'comments', 'link', 'link_text',
                              'link2', 'link2_text', 'link3', 'link3_text', 'link4', 'link4_text', 'link5', 'link5_text');
            foreach ($postvars as $key=>$elem) { if(isset($_POST[$elem])) { $$elem = $_POST[$elem]; } if(!isset($$elem)) { $$elem = ""; } }
            $news_text = str_replace("\r\n", "<br />", $news_text);
            $news_text = corebb(stripslashes($news_text),"toHTM");

            $result = array('id'            =>    1,
                            'author_id'     =>    $author_id,
                            'news_title'    =>    $news_title,
                            'news_text'     =>    $news_text,
                            'time'          =>    time(),
                            'icon_id'       =>    $icon_id,
                            'show_email'    =>    $show_email,
                            'category'      =>    $category,
                            'comments'      =>    0,
                            10     =>    $link,
                            11    =>    $link_text,
                            12    =>    $link2,
                            13    =>    $link2_text,
                            14    =>    $link3,
                            15    =>    $link3_text,
                            16    =>    $link4,
                            17    =>    $link4_text,
                            18    =>    $link5,
                            19    =>    $link5_text);
            makeNews();
        }
    }}

// Versteckt, damit nicht an den Copyrights gepfuscht wird

    if (!function_exists("showCopyright")) {
    function showCopyright() {

        global $show,
               $debug,
               $options;

        if ($debug == "ON") { print "showCopyright<br />\r\n"; }
        if (($options['show_copyright']) && ($show != "css")) {
            print "<div align=\"center\" class=\"smalltext\">\r\n";
            print "powered by Corenews Total Conversion $options[version]";
            print " &copy; 2003 by <a href=\"mailto:eebkiller[at]web.de\" class=\"smalltext\"><b>EEBKiller</b></a><br />\r\n";
            print "based up on <a href=\"http://www.coreslawn.de\" target=\"_blank\" class=\"smalltext\"><b>Corenews 2.0.1</b></a>";
            print " &copy; 2002 by <a href=\"mailto:core@coreslawn.de\" class=\"smalltext\"><b>Core</b></a>\r\n";
            print "</div>\r\n";
        }
    }}

// Hier werden alle Newspostings erstellt

    if (!function_exists("makeNews")) {
    function makeNews() {

        global $extension,
               $styledata,
               $catindex,
               $comments,
               $options,
               $result,
               $news_id,
               $PHP_SELF,
               $QUERY_STRING;
        require("config.inc".$extension);
        require("corebb".$extension);

        $dbconn = new Coresql($db_server, $db_database, $db_account, $db_password);
        $userdata = $dbconn->fetchArray("SELECT * FROM $usertable WHERE id = $result[author_id]");
        $result['news_title'] = stripslashes($result['news_title']);
// show more (Zeichengebunden)
        $news_text = stripslashes($result['news_text']);
        if (($news_id == "") && ($options['newstext_cut'] > 10) && ( strlen($news_text) > $options['newstext_cut'])) {
            $news_text = corebb($news_text, "toBB");
            $news_text = substr($news_text, 0, ($options['newstext_cut'] + 10));
            $news_parts = explode(" ", $news_text);
            $news_text = $news_parts[0]; $i = 1;
            while (strlen("$news_text $news_parts[$i]") < ($options['newstext_cut'] - 3)) {
                $news_text .= " $news_parts[$i]"; $i ++;
            }
            preg_match_all("!<a!is", $news_text, $a_begin_match, PREG_SET_ORDER);
            preg_match_all("!</a>!is", $news_text, $a_end_match, PREG_SET_ORDER);
            if (count($a_begin_match) != count($a_end_match)) {
                $news_text = preg_replace("!<a(.*)!is", "", $news_text);
            }
            $news_text = corebb($news_text, "toHTM");
            $dbconn = new Coresql($db_server, $db_database, $db_account, $db_password);
            $news_text = $news_text." ...\r\n<br />\r\n<br /><a href=\"".$PHP_SELF.$QUERY_STRING."&amp;comments=$result[id]\" class=\"news\">weiterlesen...</a>";
        }
// show more (selbst definiert)
        $news_text = preg_replace("#\[MEHR\]#is", "[MEHR]", $news_text);
        $news_parts = substr_count($news_text, "[MEHR]");
        if (($news_parts == 1) && ($news_id == "")) {
            $news_part = explode("[MEHR]", $news_text);
            $news_text = $news_part[0];
            $news_text = $news_text." ...\r\n<br />\r\n<br /><a href=\"".$PHP_SELF.$QUERY_STRING."&amp;comments=$result[id]\" class=\"news\">weiterlesen...</a>";
        } else {
            $news_text = preg_replace("#\[MEHR\]#is", "", $news_text);
        }
// -- Ende --
        if ($result['show_email']) {
            $userdata['username'] = "<a href=\"mailto:$userdata[email]\" class=\"smalltext\">$userdata[username]</a>";
        }
        if (($options['use_icons']) && ($result['icon_id'])) {
            $icondata = $dbconn->fetchArray("SELECT * FROM $icontable WHERE id = $result[icon_id]");
            $icon = "<img src=\"$options[icon_dir]$icondata[name]\" alt=\"$icondata[title]\" />";
        } else {
            $icon = "";
        }
        if ($options['comments_allowed'] && $comments == "" && ($result['comments'] == 1)) {
            if ($options['comm_extra_page']) {
                $comm_window = " target=\"_blank\"";
            } else {
                $comm_window = "";
            }
            $countcomments = $dbconn->countRows("SELECT NULL FROM $commentstable WHERE news_id = $result[id]");
            $comment = "<a class=\"navi\" href=\"".$PHP_SELF.$QUERY_STRING."&amp;comments=$result[id]#newcomment\" class=\"links\"$comm_window>$countcomments kommentar";
            if ($countcomments != 1) {
                $comment = $comment . "e";
            }
            $comment = $comment . "</a>";
        } elseif (!$options['comments_allowed'] || ($result['comments'] == 0)) {
            $comment = "<span class=\"links\">Komm. deaktiviert</span>";
        } else { $comment = "<span class=\"links\">kommentare:</span>"; }
        $l = 0; $link = "";
        for ($i = 0; $i < 5; $i ++) {
            if ($result[10 + $i * 2] != "") {
                $l ++ ;  if ($l > 1) { $link = $link.$options['link_separator']; }
                $link = $link." <a href=\"".$result[10 + $i * 2]."\" target=\"_blank\" class=\"links\">".$result[11 + $i * 2]."</a>";
            }
        }
        if ($l == 0) { $link = "Keiner"; }
        if ($l <= 1) { $linkcount = "Link:";  }
        else         { $linkcount = "Links:"; }
        $category = $catindex['name'];

        $rows = $dbconn->countRows("SELECT * FROM $smilietable");
        for($smilie_id = 1; $smilie_id <= $rows; $smilie_id ++) {
            $correctdata = 0;
            while($correctdata < 1) {
                $data = $dbconn->fetchArray("SELECT * FROM $smilietable WHERE id = $smilie_id");
                if ($data['id'] == "") { $smilie_id ++; $rows ++; } else { $correctdata = 1; }
            }
            $comment_repl = "<img src=\"$options[smilie_dir]$data[name]\" border=\"0\" alt=\"$data[title]\" />";
            $news_text = str_replace($data['code'], $comment_repl, $news_text);
        }





        // voting funktion

function return_topflop($id) {

    global $newstable;
    $query = mysql_query("SELECT top,flop FROM $newstable WHERE id = $result[id]");
    $vote = mysql_fetch_array($query);

    if($votegesamt<=0){$gerundet=round((($vote[top]*100)/($vote[top]+$vote[flop])));}

switch(true)
{
       case ($gerundet <=  0): return "0"; break;
       case ($gerundet <= 20): return "1"; break;
       case ($gerundet <= 40): return "2"; break;
       case ($gerundet <= 60): return "3"; break;
       case ($gerundet <= 80): return "4"; break;
       default : return "5"; break;
}
}


		// voting ausgabe
        $voting = "<a class=\"navi\" href=\"deadlink.php?funktion=top&id=$result[id]\" target=\"_blank\">+</a> <img src=\"".return_topflop($_GET["id"]).".gif\" border=\"0\"> <a class=\"navi\" href=\"deadlink.php?funktion=flop&id=$result[id]\" target=\"_blank\">-</a>";






        $dead = "<a class=\"navi\" href=\"deadlink.php?id=$result[id]\" target=\"_blank\">deadlink?</a>";

        $close = $dbconn->close();
        $linkus = "<a href=\"".$PHP_SELF.$QUERY_STRING."&amp;news_id=$result[id]\" target=\"_blank\" class=\"smalltext\">News linken</a>";
        $news = str_replace("{category}", $category, $styledata['tpl_main']);
        $news = str_replace("{title}", $result['news_title'], $news);
        $news = str_replace("{news}", $news_text, $news);
        $news = str_replace("<a ", "<a class=\"news\" ", $news);
        $news = str_replace("{icon}", $icon, $news);
        $news = str_replace("{user}", $userdata['username'], $news);
        $news = str_replace("{time}", date($options['date_format'], $result['time']), $news);
        $news = str_replace("{comments}", $comment, $news);
        $news = str_replace("{dead}", $dead, $news);
        $news = str_replace("{voting}", $voting, $news);
        $news = str_replace("{links}", $link, $news);
        $news = str_replace("{linkcount}", $linkcount, $news);
        $news = str_replace("{linkus}", $linkus, $news);
        $news = str_replace("{align}", $options['news_alignment'], $news);
        if ($options['php_allowed']) {
            $news = str_replace('"', '\"', $news);
            $news = str_replace('?>', 'print "', $news);
            $news = str_replace('<?php', '"; ', $news);
            $news = 'print "'.$news.'";';
            $news = eval($news);
        }
        print $news;
    }}

// Lastnews

    if (!function_exists("showLastNews")) {
    function showLastNews() {

        global $extension,
               $styledata,
               $QUERY_STRING,
               $PHP_SELF,
               $options;
        require("config.inc".$extension);

        $dbconn = new Coresql($db_server, $db_database, $db_account, $db_password);
        $catrows = $dbconn->countRows("SELECT * FROM $categorytable");
        $querypart = "WHERE";
        for ($i = 1; $i <= $catrows; $i++ ) {
            $categorydata = $dbconn->fetchArray("SELECT * FROM $categorytable WHERE id = $i");
            if ($categorydata['internal'] == 1) {
                $querypart = $querypart." category != $i AND";
            }
        }
        if (substr($querypart, -3, 3) == "AND") { $querypart = substr($querypart, 0, -3); }
        $newsdata = $dbconn->fetchMultiple("SELECT * FROM $newstable $querypart ORDER BY time DESC LIMIT 0,$options[lastnews_num]");
        $lastnews = "";
        if ($newsdata != "") {
            foreach ($newsdata as $key=>$elem) {
                $catindex = $dbconn->fetchArray("SELECT * FROM $categorytable WHERE id = $elem[category]");
                $authordata = $dbconn->fetchArray("SELECT * FROM $usertable WHERE id = $elem[author_id]");
                if (($catindex['internal'] != 1) && ($elem['is_confirmed'] == 1)) {
                    $title = $elem['news_title'];
                    if (strlen($title) > $options['lastnews_cut']) {
                        $title = substr($title, 0, ($options['lastnews_cut'] - 3))."...";
                    }
                    $title = "<a href=\"http://".$options['domain'].$options['news_root'].$QUERY_STRING."&amp;news_id=$elem[id]\" class=\"news\">$title</a>";
                    $lastnews = $lastnews.(str_replace("{title}", $title, $styledata['tpl_lastnews']));
                    $lastnews = str_replace("{author}", $authordata['username'], $lastnews);
                    $lastnews = str_replace("{category}", $catindex['name'], $lastnews);
                    $lastnews = str_replace("{time}", date("G:i", $elem['time']), $lastnews);
                    $lastnews = str_replace("{date}", date("j. n. Y", $elem['time']), $lastnews)."\r\n";

                }
            }
            $close = $dbconn->close();
            print $lastnews;
        } else { print "<div class=\"news\" align=\"center\"><b>Keine News gefunden!</b></div>\r\n<br />\r\n"; }
    }}

?>


PS: War heute im Buchladen und habe mir zwei PHP Bücher geholt,
dann wollen wir mal... :)
 
Zurück