Category Select and Per Page problems

I’m not a seasoned coder in PHP, and I am having problems with one of the scripts on my site. It’s basically a database of “homebrew” games and applications everything is divided by categories. The problem I am having is that the selection doesn’t work properly. Say for instance you are in the “Nintendo DS” section for example. The url would be:

http://www.modawii.com/homebrew/categoryResults.php?cat=5

If you were to try and show 15 items per page as opposed to the default of 5 per page, it would send you to the wrong url:

http://www.modawii.com/homebrew/categoryResults.php?cnt=15

What it should have done was this:

http://www.modawii.com/homebrew/categoryResults.php?cat=5&cnt=15
There are also some other similar problems I am having as well, like when I click the “>>” button which takes you to the next page it simply adds another “?page=1” to the end of the url everytime I click it like this:

http://www.modawii.com/homebrew/categoryResults.php?cat=5?page=1?page=1?page=1

When it should do this:

http://www.modawii.com/homebrew/categoryResults.php?cat=5&page=2

I hope you are still following me on this, I am trying to explain the best that I can.

You can take a look at the page and see what I mean by visiting http://www.modawii.com/homebrew and playing around with it yourself.

Here is my code for my “categoryResults.php”:

<?

include("./config/config.php");

if($_GET['cat']){
	$WHERE = "Category='".$_GET['cat']."'";
}
else{
	header("Location: ./index.php");
}

$page = "search homebrew";
include("./config/header.php");

$pg = $_GET['page'];

if(!$_GET['cnt']){$cnt = 5;}
else{$cnt = $_GET['cnt'];}

if(!$pg){$pg = 1;}
$count = (($pg * $cnt)-$cnt);
if($count < 0){$count = 0;}
$i=0;
$query = mysql_query("SELECT ID,Title,Category,DishImage,description,ratingStr FROM ".$cfg['homebrewTable']." WHERE ".$WHERE." AND approved='yes' LIMIT ".$count.",".$cnt);
while(list($ID,$title,$category,$image,$description,$ratingStr)=mysql_fetch_row($query)){
	echo "<p>";
	echo smallHomebrewTable($ID,$title,$category,$image,$description,$ratingStr,$cfg['bodyWidth']);
	$i++;
}
echo table(1,0,$cfg['bodyWidth']);
echo tr();
	echo td(1,"basicText","left",0,0,0,0," style='padding:5px;'").perPageSelect($cnt,"categoryResults.php","&cat=".$_GET['cat']).td(2);
	echo td(1,"basicText","right",0,0,0,0," style='padding:5px;'");
		echo pageLinks($cfg['homebrewTable'],"./categoryResults.php?cat=".$_GET['cat'],$WHERE,$pg,$count,$cnt);

	echo td(2);
echo tr(2);
echo table(2);


include("./config/footer.php");

?>

This has been driving me nuts for days now and I can’t seem to get it working properly. Any help would be greatly appreciated. Thanks! :D

That page looks to be working fine. I can’t find any of the issues you’re describing.

lol, this post can be disregarded. I spent all day yesterday nabbing those bugs. I got it working for the most part. Thanks for looking anyways.

Sponsor our Newsletter | Privacy Policy | Terms of Service