/    Sign up×
Community /Pin to ProfileBookmark

mysql_num_rows dosent return right value when duplicated scrpits are running

Hi!

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.

[code=php]
<?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);
}
?>[/code]

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@rootFeb 20.2015 — Have you tried echoing your completed query string to ensure that you have a query string thats valid?

Also... mysql_* functions have been replaced by mysql[COLOR="#FF0000"][B]i[/B][/COLOR]_* functions, this is because of PHP updates on most webservers will no longer support mysql_* functions, in other words they have been depreciated.

You also have to escape any strings you want to use in your query to ensure it does not create unexpected results.
Copy linkTweet thisAlerts:
@quarskelauthorFeb 20.2015 — Have you tried echoing your completed query string to ensure that you have a query string thats valid?

Also... mysql_* functions have been replaced by mysql[COLOR="#FF0000"][B]i[/B][/COLOR]_* functions, this is because of PHP updates on most webservers will no longer support mysql_* functions, in other words they have been depreciated.

You also have to escape any strings you want to use in your query to ensure it does not create unexpected results.[/QUOTE]


The wierd thing is that one of the script work and on dosent.(check the site (http://gamerefresh.se) the right side. "turneringar" works but "servrar" dosent) even when its using the exactly same script...

So it dosent feels like it is a string problem?
Copy linkTweet thisAlerts:
@rootFeb 20.2015 — What you don't feel is a problem could very well be the problem, you should not dismiss or overlook this, checking the output of your script may reveal something and eliminate a problem in your scripts processing.
Copy linkTweet thisAlerts:
@quarskelauthorFeb 20.2015 — What you don't feel is a problem could very well be the problem, you should not dismiss or overlook this, checking the output of your script may reveal something and eliminate a problem in your scripts processing.[/QUOTE]

I dont know what to do...
Copy linkTweet thisAlerts:
@rootFeb 20.2015 — You take the variable that is the query string and simply output it with an echo or print.

at this point $ergebnis=safe_query("SELECT you have a query string, simply copy and paste above that if() conditional element.

[code=php]echo "SELECT * FROM ".PREFIX."news WHERE published='1' ".$only." AND intern<=".isclanmember($userID)." AND category='4' ORDER BY date DESC LIMIT 0,".$maxheadlines;[/code]
Copy linkTweet thisAlerts:
@quarskelauthorFeb 20.2015 — What you don't feel is a problem could very well be the problem, you should not dismiss or overlook this, checking the output of your script may reveal something and eliminate a problem in your scripts processing.[/QUOTE]

Yeah, ive done that.

When it works it gives me this: Resource id #151

When it doesnt work this shows up: Resource id #191

I have no idea what that means.

When i run the "second" script alone it gives me Resource id #151 but when i run it as the second script on the page it gives me id #191..
Copy linkTweet thisAlerts:
@rootFeb 21.2015 — Can you post the actual output string that you are using as a query. It does help with troubleshooting issues.
Copy linkTweet thisAlerts:
@quarskelauthorFeb 21.2015 — Thanks!

I solved it, it whas the "$only" thing that read in only LoL games.. so i edited that?
Copy linkTweet thisAlerts:
@rootFeb 21.2015 — Thats great. I take it that you are fairly recent starter in programming then? If you are, the following is a way of speeding up debugging code, each language has its debugging tools, so does javascript.

I suggest that you read up on troubleshooting and what you can use for tracking bugs in code. When you recycle scripts, errors creep in, remembering how to use the different types of debugging methods to speed up your code building. When you code, especially functions, try to standardize a set of rocksolid functions that you can just include in to your other scripts, thats what I find useful to me, find what suits you. Just google the subject.

The quickest way is to output the content of the variable with one of the var_dump or similar methods to see what the vriable contains. I find echoing first is quickest to determine if I need to dump the variable contents.

You then have the try & catch method of controlling errors in functions, giving you the option to output a custom error message or just the error report to the screen or a log...

Variables should be the same consistency throughout your code, once you adopt a method, stick to it and tracking your own bugs will be quicker, if working as part of a team, again, adopt a style that the whole team uses, these are

$singlecace - harder to read but good for short variables in some scripting circumstances

$camelCase - better to read, more Capitalized words can be added to extend naming variables

$underscore_case - very common, used in many programming languages

DEFINED_CASE - a defined type that is either system global or a user defined type

You should also read up on the defined types that are system globals types like $_SERVER or constant and boolean types like true

That is just some of the methods I employ in debugging scripts I write, I will look at someones script and create my own version and how I would do it by ordering the program flow as needed.
×

Success!

Help @quarskel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...