A little help. Custom counter... (Debugging)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Sky
Forum Commoner
Posts: 71
Joined: Wed Oct 02, 2002 4:00 pm

A little help. Custom counter... (Debugging)

Post by Sky »

(EDIT: I have been trying to debug this, but unsuccessfully. So here I post)
YepYep, learning more php and now mySQL :D

I've converted my user database, news, and menu to SQL. now for the counter. Here's my current code, and I keep getting the elseif outcome.

Code: Select all

<?php
function counter($page = 'misc')
{	
	global $_users; //Make user info global
	$currenthits = 0; //Preset current hits
	if(!$_users['__']) //Check to see if user info is already there
		getUserInfos(); //Get user info
	else {} //Else do nothing
	
	$queryA = "SELECT count FROM `site_counter` WHERE page='" .$page ."'";
	$queryC = "INSERT INTO `site_counter` (`count`, `page`) VALUES ('1', '".$page."');"; //Define querys
	$currenthits = mysql_query($queryA) or mysql_query($queryC) or die('Query A/C Error:'.mysql_error()); //Get count OR make new entry OR die. I'm not sure on the syntax with inline logic and parenthesies. Someone have a good tutorial?
	
	if(!$new and (is_int($currenthits) and isset($currenthits))) {//Check IsInt&Isset
		$currenthits++;// Incriment
		$queryB = "UPDATE `site_counter` SET count='" .$currenthits ."' WHERE page='" .$page ."'";//Define query
		mysql_query($queryB) or die('Update: '.mysql_error()); //Run or die
	}
	
	elseif (isset($currenthits) and !is_int($currenthits)) //Check for set&not int
		$currenthits = '2::1'; //(2:: for debug purposes)
	
	else {
		$currenthits = '3::1'; //else
	}	
	return $currenthits; //return
}
?>
scr0p
Forum Newbie
Posts: 23
Joined: Mon May 05, 2003 6:49 pm
Location: NY

Post by scr0p »

you dont need that else{}, you can jsut have
if(x == 1016)
then do this
the line right under will be the only line that gets executed if the 'if' statement is true
User avatar
Sky
Forum Commoner
Posts: 71
Joined: Wed Oct 02, 2002 4:00 pm

Post by Sky »

I know that, but that's a habbit... and being a habbit, it hasn't affected anything. Should it? Thanks at any rate
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Where does the $new variable come from? You also don't seem to have used mysql_fetch_assoc() or anything else in order to get the result of the select query into a useable form (i.e. so it's not a Resouce ID).

Could you explain a bit about what the code is supposed to be doing?

Mac
User avatar
Sky
Forum Commoner
Posts: 71
Joined: Wed Oct 02, 2002 4:00 pm

Post by Sky »

That... Umm... Might be it :oops: and $new....
I must have left that in there! Another error... 8O

Thanks T :)
Post Reply