0

I need help to solve a problem. I have this script twice on my page in two diffrent divs. The first script works fine and the second also, but when i run the script at the same time on the page only the first script works.When it work it returns 1 but now it returns 0.

The scripts is in diffrent files. One should be showning news category 4 and one news category 5.

Why doesnt it work?

Thankful for help.

<?php
$only = '';
if(isset($sc_categoryID) and $sc_categoryID) $only = "AND category='".$sc_categoryID."'";
if(isset($sc_rubricID) and $sc_rubricID) $only = "AND rubric='".$sc_rubricID."'";
if(isset($sc_game) and $sc_game) $only = "AND game='".$sc_game."'";


$ergebnis=safe_query("SELECT * FROM ".PREFIX."news WHERE published='1' ".$only." AND intern<=".isclanmember($userID)." AND category='4' ORDER BY date DESC LIMIT 0,".$maxheadlines);
if(mysql_num_rows($ergebnis)){
    echo '<ul>';
    $n=1;
    while($ds=mysql_fetch_array($ergebnis)) {
        $date=date("d.m.Y", $ds['date']);
        $time=date("H:i", $ds['date']);
        $news_id=$ds['newsID'];

        if($n%2) {
            $bg1=BG_1;
            $bg2=BG_2;
        }
        else {
            $bg1=BG_3;
            $bg2=BG_4;
        }

        if(file_exists('images/games/'.$ds['game'].'.gif')) $pic = '<img src="images/games/'.$ds['game'].'.gif" alt="'.$ds['game'].'" />';
        $game=$ds['game'];

        $category='';
        $newscategory=safe_query("SELECT categoryID, category FROM ".PREFIX."news_category WHERE categoryID='".$ds['category']."'");
        while($dr=mysql_fetch_array($newscategory)) {
            $categoryname=$dr['category'];
            $categoryname_link = getinput($categoryname);
        }

        $message_array = array();
        $query=safe_query("SELECT n.*, c.short AS `countryCode`, c.country FROM ".PREFIX."news_contents n LEFT JOIN ".PREFIX."countries c ON c.short = n.language WHERE n.newsID='".$ds['newsID']."'");
        while($qs = mysql_fetch_array($query)) {
            $message_array[] = array('lang' => $qs['language'], 'headline' => $qs['headline'], 'message' => $qs['content'], 'country'=> $qs['country'], 'countryShort' => $qs['countryCode']);
        }
        $showlang = select_language($message_array);

        $languages='';
        $i=0;
        foreach($message_array as $val) {
            if($showlang!=$i)   $languages.='<span style="padding-left:2px"><a href="index.php?site=news_comments&amp;newsID='.$ds['newsID'].'&amp;lang='.$val['lang'].'"><img src="images/flags/'.$val['countryShort'].'.gif" width="18" height="12" border="0" alt="'.$val['country'].'" /></a></span>';
            $i++;
        }

        $lang=$message_array[$showlang]['lang'];

        $headlines=$message_array[$showlang]['headline'];

        if(mb_strlen($headlines)>$maxheadlinechars) {
            $headlines=mb_substr($headlines, 0, $maxheadlinechars);
            $headlines.='...';
        }

        /* Comments - Mod */
        $comments = $_POST['comments'];
        if($ds['comments']) {
            if($ds['cwID']) {  // CLANWAR-NEWS
                $anzcomments = getanzcomments($ds['cwID'], 'cw');
                $replace = Array('$anzcomments', '$url', '$lastposter', '$lastdate');
                $vars = Array($anzcomments, 'index.php?site=clanwars_details&amp;cwID='.$ds['cwID'], clearfromtags(getlastcommentposter($ds['cwID'], 'cw')), date('d.m.Y - H:i', getlastcommentdate($ds['cwID'], 'cw')));

                switch($anzcomments) {
                case 0: $comments = str_replace($replace, $vars, $_language->module['no_comment']); break;
                case 1: $comments = str_replace($replace, $vars, $_language->module['comment']); break;
                default: $comments = str_replace($replace, $vars, $_language->module['comments']); break;
                }
            }
            else {
                $anzcomments = getanzcomments($ds['newsID'], 'ne');
                $replace = Array('$anzcomments', '$url', '$lastposter', '$lastdate');
                $vars = Array($anzcomments, 'index.php?site=news_comments&amp;newsID='.$ds['newsID'], clearfromtags(html_entity_decode(getlastcommentposter($ds['newsID'], 'ne'))), date('d.m.Y - H:i', getlastcommentdate($ds['newsID'], 'ne')));

                switch($anzcomments) {
                case 0: $comments = str_replace($replace, $vars, '0'); break;
                case 1: $comments = str_replace($replace, $vars, '1'); break;
                default: $comments = str_replace($replace, $vars, '$anzcomments'); break;
                }
            }
        }
        else $comments='Closed';

        /* End - Comments Mod*/

        $headlines=clearfromtags($headlines);

        if($ds['live'] == 1) $live = '<font style="text-decoration:blink; font-weight: bold; color:#009900;">*Live*</font>';
        else $live = '';

        eval ("\$sc_headlines = \"".gettemplate("sc_headlines")."\";");
        echo $sc_headlines;

        $n++;
    }
    echo '</ul>';
    unset($sc_rubricID);
    unset($sc_categoryID);
    unset($sc_game);
}
?>
Quarskel
  • 27
  • 4
  • 1
    What does `safe_query` do? what does it return? Also, quit using the `mysql_*` API, its deprecated and not good. Check out `PDO` or `mysqli` instead. – Jite Feb 20 '15 at 12:42
  • 1
    What kind of bad value is `mysql_num_rows` returning? – Barmar Feb 20 '15 at 12:45
  • Barmar, When it work it returns 1 but now it returns 0. – Quarskel Feb 20 '15 at 12:46
  • So maybe there's nothing that matches all the criteria in category 5. If you echo the query and execute it by hand, does it return anything? – Barmar Feb 20 '15 at 12:47
  • There is nothing to do with the category cause it works fine when i just run one of them. but when i run both the same time only one of them works. – Quarskel Feb 20 '15 at 13:04
  • echo the SELECT statement. Then go to the mysql commandline tool (or phpmyadmin) and perform the query outside the context of you code. What does the SELECT look like? What does it return? – Rick James Feb 21 '15 at 02:30

0 Answers0