How to create a Counter for Catagory Itemsphp & html - catagory counter
38 Replies - 2148 Views - Last Post: 03 April 2009 - 11:56 AM
#1
How to create a Counter for Catagory Items
Posted 30 March 2009 - 01:01 PM
I have purchased a script and i am trying to add a catagory counter for each catagory, or a counter that adds to the catagory automaticly....
I know my description is very bad, but i just want to be able to make a catagory counter for my catagorys.
how would i do this ?
Replies To: How to create a Counter for Catagory Items
#2
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 01:10 PM
dwrlox, on 30 Mar, 2009 - 12:01 PM, said:
I have purchased a script and i am trying to add a catagory counter for each catagory, or a counter that adds to the catagory automaticly....
I know my description is very bad, but i just want to be able to make a catagory counter for my catagorys.
how would i do this ?
can you post the part of the script that governs the categories?
and the template for the category view/list?
#3
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 01:15 PM
richiebee, on 30 Mar, 2009 - 12:10 PM, said:
dwrlox, on 30 Mar, 2009 - 12:01 PM, said:
I have purchased a script and i am trying to add a catagory counter for each catagory, or a counter that adds to the catagory automaticly....
I know my description is very bad, but i just want to be able to make a catagory counter for my catagorys.
how would i do this ?
can you post the part of the script that governs the categories?
and the template for the category view/list?
I am sorry, but i have 4 files for my catagorys... should i post them all.
?
#4
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 01:36 PM
dwrlox, on 30 Mar, 2009 - 12:15 PM, said:
richiebee, on 30 Mar, 2009 - 12:10 PM, said:
dwrlox, on 30 Mar, 2009 - 12:01 PM, said:
I have purchased a script and i am trying to add a catagory counter for each catagory, or a counter that adds to the catagory automaticly....
I know my description is very bad, but i just want to be able to make a catagory counter for my catagorys.
how would i do this ?
can you post the part of the script that governs the categories?
and the template for the category view/list?
I am sorry, but i have 4 files for my catagorys... should i post them all.
?
yes as long as you put them in code brackets
also where did you purchase them from (name of script)?
#5
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 02:12 PM
as i expected it's php driven...not my expertise
<?php
class Display_DCategory
{
function allCat($arr)
{
include 'admin/cache/sitesettings.php';
if(isset($_SESSION['language']) && $_SESSION['language']!='')
$lang = $_SESSION['language'];
else
$lang = $sitesettings['language'];
$path='classes/Lib/Local/'.$lang.'/localization.php';
include $path;
$output="";
$cont=count($arr);
$query=new Lib_Query();
for($i=0; $i<$cont; $i++)
{
$sql="SELECT subcat_name FROM subcategories WHERE subcat_parent=".$arr[$i]['cat_id'];
if($query->executeQuery($sql))
$link = "index.php?do=allcat&id=".($arr[$i]['cat_id']);
else
$link = "index.php?do=search&id=".($arr[$i]['cat_id']);
$output .='<a href="'.$link.'">'.stripslashes($arr[$i]['cat_name']).'</a>';
}
return $output;
}
function showSub($arr)
{
include 'admin/cache/sitesettings.php';
if(isset($_SESSION['language']) && $_SESSION['language']!='')
$lang = $_SESSION['language'];
else
$lang = $sitesettings['language'];
$path='classes/Lib/Local/'.$lang.'/localization.php';
include $path;
$obj=new Core_Category_CCategory();
$output="";
$cont=count($arr);
for($i=0;$i<$cont;$i++)
{ //echo"<pre>";
$sub=$obj->showSubCat($arr[$i]['subcat_id']);
$count = count($sub);
if($count > 0)
$link = "index.php?do=allcat&id=".($arr[$i]['subcat_id']);
else
$link = "index.php?do=search&id=".($arr[$i]['subcat_id']);
$output .='<td width=20% align="left" class="buy_txt" valign="top"><a href="'.$link.'" class="buy_head_link">'.stripslashes($arr[$i]['subcat_name']).'</a><br>';
if(count($sub) > 3)
$count = 3;
else
$count = count($sub);
if($count==0)
{
$output .='<a href="#" >'.$localization['ENG1894'].'</a>';
}
for($j=0;$j<$count;$j++)
{
//$output .='<li><a href="?do=search&pid='.($arr[$i]['subcat_id']).'&id='.$sub[$j]['subcat_id'].'" class="list_style_link">'.$sub[$j]['subcat_name'].'</a></li> ';
$sub1=$obj->showSubCat($sub[$j]['subcat_id']);
$count_sub = count($sub1);
// if($count_sub > 0 )
// $sub_link = "?do=allcat&id=".$sub[$j]['subcat_id'];
// else
$sub_link = "?do=allcat&id=".$sub[$j]['subcat_id'];
$output .='<a href="'.$sub_link.'" class="list_style_link">'.stripslashes($sub[$j]['subcat_name']).'</a> | ';
}
if(count($sub) > 0)
$output .=' <a href="'.$link.'" class="list_style_link">'.$localization['ENG1512'].' ...</a>';
$output .='</td>';
if($i%3==0 && $i>0)
$output .='</tr>
<tr>
<td colspan=3 height=10></td>
</tr>
<tr>';
}
return $output;
}
}
?>
the second one
<?php
class Core_Category_CCategory
{
function showAll()
{
include('classes/Display/DCategory.php');
$sql="SELECT * FROM categories ORDER BY cat_name LIMIT 0 , 25";
$query=new Lib_Query();
$query->executeQuery($sql);
$query->records;
$this->data['showcat'] =Display_DCategory::allCat($query->records);
$this->makeConstants($this->data);
}
function showCat()
{
$components = new Lib_Components();
if(isset($_GET['id']))
$id = $_GET['id'];
else
$id = '';
$this->data['allcat'] = $components->createComponent('combobox',$this->getListValues('category'),'name=id class=category_box',$id);
$this->makeConstants($this->data);
}
function showMain()
{
include('classes/Display/DCategory.php');
if($_GET['id'] == 'all')
$_GET['id'] = 0;
else
$_GET['id']=$_GET['id'];
$arr=$this->showSubCat($_GET['id']);
$sql="SELECT subcat_name FROM subcategories WHERE subcat_id=".$_GET['id'];
$query=new Lib_Query();
if($query->executeQuery($sql))
$this->data['maincat']= stripslashes($query->records[0]['subcat_name']);
else
$this->data['maincat']= "All Category";
$this->data['showallcat'] =Display_DCategory::showSub($arr);
$this->makeConstants($this->data);
}
function showSubCat($catid,$max='',$hassubcat='',$matchwith='')
{
$sub=array();
$matchwith=($matchwith) ? " AND subcat_name LIKE '%$matchwith%'" : "";
$max=($max) ? "LIMIT 0,$max" : "";
$sql="SELECT * FROM `subcategories` WHERE subcat_parent=$catid $max $matchwith ORDER BY subcat_name ASC";
$query=new Lib_Query();
$query->executeQuery($sql);
if(count($query->records)>0)
{
if($hassubcat)
{
$cout=count($query->records);
for($i=0;$i<$cout;$i++)
{
$sql="SELECT * FROM `subcategories` WHERE subcat_parent='".$query->records[$i]['subcat_id']."' ORDER BY subcat_name ASC";
$query1=new Lib_Query();
if($query1->executeQuery($sql))
$sub[]=$query->records[$i]['subcat_id'];
}
if($sub)
$this->getSub($sub,$matchwith);
}
else
return $query->records;
}
}
function subcat($catid)
{
$sl="SELECT subcat_id,subcat_name FROM `subcategories` WHERE subcat_parent=$catid LIMIT 0,3";
$q=new Lib_Query();
$q->executeQuery($sl);
if(count($q->records)>0)
return $q->records;
else
{
$sl="SELECT subcat_id,subcat_name FROM `subcategories` ORDER BY subcat_name ASC LIMIT 0,3";
$q->executeQuery($sl);
return $q->records;
}
}
function getSub($aryid,$lke='')
{
$sql="SELECT * FROM `subcategories` WHERE ";
foreach ($aryid as $id)
$sql .= " subcat_id=$id or ";
$sql = rtrim($sql," or ");
$sql .=$lke;
$query=new Lib_Query();
if($query->executeQuery($sql))
($query->records);
}
function makeConstants($fields,$prefix='')
{
//print_r($fields);
foreach ($fields as $key=>$item)
{
if(!defined($prefix.strtoupper($key)))
define($prefix.strtoupper($key),$item);
}
}
function getListValues($name)
{
if($name == 'category')
{
$sql = "SELECT * FROM categories ORDER BY cat_name ASC";
$cquery = new Lib_Query();
if($cquery->executeQuery($sql))
$records = $cquery->records;
$category = array("all"=>"All Categories");
for ($i=0;$i<count($records);$i++)
$category[$records[$i]['cat_id']] = stripslashes($records[$i]['cat_name']);
return $category;
}
}
function listCat($arr)
{
//echo "<pre>";
//print_r($arr);
$cnt=count($arr);
$output='';
$newarr = array();
$newarrname = array();
for($i=0;$i<$cnt;$i++)
{
// echo $arr[$i][0]['subcat_id'],"</br>";
if($arr[$i][0]['subcat_id'] && !in_array($arr[$i][0]['subcat_id'],$newarr))
{
$sql="SELECT subcat_parent,subcat_name FROM subcategories WHERE subcat_id ='".$arr[$i][0]['subcat_id']."' ORDER BY subcat_name ASC";
$qry=new Lib_Query();
if($qry->executeQuery($sql))
{
if(!in_array($qry->records[0]['subcat_parent'],$newarr))
{
$newarr[] = $qry->records[0]['subcat_parent'];
$s="SELECT subcat_name,subcat_id FROM subcategories WHERE subcat_id ='".$qry->records[0]['subcat_parent']."' ORDER BY subcat_name ASC";
$q=new Lib_Query();
$q->executeQuery($s);
if(!in_array($q->records[0]['subcat_name'],$newarrname))
{
$newarrname[] = $q->records[0]['subcat_name'];
$output .= '<div class="result_title">'.stripslashes($q->records[0]['subcat_name']).'</div>';
for($j=0;$j<count($arr[$i]);$j++)
{
$output .= '<div class="leftnav_link"><a href="?do=search&tid=1&id='.$arr[$i][$j]['subcat_id'].'">'.stripslashes($arr[$i][$j]['subcat_name']).'</a> </div>';
}
}
}
}
}
}
return $output;
}
function getParent($id)
{
$sql="SELECT subcat_id,subcat_name,subcat_parent FROM subcategories WHERE subcat_id='".$id."' ORDER BY subcat_name ASC";
$qrr=new Lib_Query();
$qrr->executeQuery($sql);
//print_r($qrr->records);
if($qrr->records[0]['subcat_parent']!=0)
{
$_SESSION['ar'] .= stripslashes($qrr->records[0]['subcat_name'])."/";
$this->getParent($qrr->records[0]['subcat_parent']);
}
else
$_SESSION['ar'] .= stripslashes($qrr->records[0]['subcat_name']);
return true;
}
}
?>
the 3rd one :
<?php
class Model_MCategory
{
function showCat()
{
include('classes/Core/Category/CCategory.php');
include_once('classes/Core/Home/CRecentlylist.php');
include_once('classes/Core/Home/CFeaturedListing.php');
include_once('classes/Core/Home/CHot.php');
include("classes/Core/Validation/CheckInputs2.php");
include_once('classes/Lib/ImageFunctions.php');
new Core_Validation_CheckInputs2('allcat');
$default=new Core_Category_CCategory();
$default->showMain();
$default->showCat();
$featured=new Core_Home_CFeaturedListings();
$featured->showFeatured();
$recentlist = new Core_Home_CRecentlylist();
$recentlist->showRecent();
$hotlisting = new Core_Home_CHot();
$hotlisting->showHot();
include('templates/buy_allcat.php');
}
}
?>
This post has been edited by richiebee: 30 March 2009 - 02:14 PM
#6
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 02:27 PM
#7
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 03:11 PM
categories (number of categories)
list of categories
Attached image(s)
#8
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 03:21 PM
richiebee, on 30 Mar, 2009 - 02:11 PM, said:
categories (number of categories)
list of categories
-
Basicly what i would like to do is add a counter to each catagory telling you how many items are in catagorys.... So that people can see where there are items are where not... because some might be empty and its anoying for a user not to be able to see it
#9
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 03:43 PM
http://us2.php.net/mysql_num_rows
Returns the number of rows in a given column, thus letting the person know how many items are there.
--
Greg
#10
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 03:54 PM
gregwhitworth, on 30 Mar, 2009 - 02:43 PM, said:
http://us2.php.net/mysql_num_rows
Returns the number of rows in a given column, thus letting the person know how many items are there.
--
Greg
Greg, that looks very promising, thank you indeed.. this is a great addition to my learning sites... thank you Sir.
also, would you be able to tell me where about to put this code, as i've tryd this one :
<?php
function get_rows ($table_and_query) {
$total = mysql_query("SELECT COUNT(*) FROM $table_and_query");
$total = mysql_fetch_array($total);
return $total[0];
}
?>
and well i put it at the top of the script
#11
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 04:08 PM
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM $table_and_query", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
?>
If you show the exact query you're doing I could help more.
#12
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 04:15 PM
gregwhitworth, on 30 Mar, 2009 - 03:08 PM, said:
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM $table_and_query", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
?>
If you show the exact query you're doing I could help more.
hmm i dont even know where to start thats my problem
#13
Re: How to create a Counter for Catagory Items
Posted 30 March 2009 - 08:10 PM
// This is the connection to the database, you should already have something along these lines
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);
// This is the query to the db that selects the column you want to count
$result = mysql_query("SELECT * FROM $table_and_query", $link);
// this is the variable that holds the number of rows within the column
$num_rows = mysql_num_rows($result);
// This echo's out the variable that you created
echo "$num_rows Rows\n";
#14
Re: How to create a Counter for Catagory Items
Posted 31 March 2009 - 07:50 AM
Quote
Thank you for your replys and help.
I am not fully understand where abouts to put the code in the code... You see i am pretty new to this, and well.... its a little foreign to me
If you wouldnt mind telling me where about the code should be placed or where abouts that would help allot.
thank you very much
The pages that richie bee posted above, can you name them for me, so that I know what I can see and what I can't. I can show you where you should throw it in and then echo out your information at least. And just so you know I am no php wizz, so along the way hopefully others will check it out and maybe even give you some helpful tips.
--
Greg
#15
Re: How to create a Counter for Catagory Items
Posted 31 March 2009 - 07:56 AM
|
|

New Topic/Question
Reply




MultiQuote




|