sagnik Posted July 16, 2017 Posted July 16, 2017 I've a problem with my code. I want to fetch rows from mysql by category. I've 3 tables (categories,subcategories & childcategories). If the code works properly, it will look like, categories=parent table, subcategories=children table of categories, childcategories=children of subcategories and sibling table of categoriescid,scid,ccid=unique numberscid=categories.cid (10digit), scid=subcategories.scid (8digit), ccid=childcategories.ccid (6digit) HOW IT WILL LOOK IN HTML OUTPUT: IF EVERY TABLE HAS CHILD ELEMENTS:- item-1 - item-1a - item-1a1 - item-1b - item-1b1 IF 1ST ROW IS A CHILD OF SUBCATEGORIES & 2ND ROW OF SUBCATEGORIES DOESN'T HAVE ANY CHILD ELEMENTS:- item-1 - item-1a - item-1a1 - item-1b IF 1ST ROW IS A CHILD OF CATEGORIES & 2ND ROW OF CATEGORIES DOESN'T HAVE ANY CHILD ELEMENTS:- item-1 - item-1a- item-2 IF ANY OF CATEGORIES DOESN'T HAVE ANY CHILD ELEMENTS:- item-1- item-2 HOW IT LOOKS IN PHPMYADMIN:table:categories table:subcategoriestable:childcategories HERE IS THE CODES:panels.php <?php $db2 = $wnd->getDatabase("listings"); $wn = new WhatsNew($db2); foreach ($wn->getCategories() as $key => $cat) { if ($cat['subcats'] > 0) { if ($cat['childcats'] > 0) { echo '<div data-role="collapsible" data-inset="false" data-collapsed-icon="plus" data-expanded-icon="minus" data-iconpos="right" id="' . $cat['id'] . '">'; if ($cat['status'] == '2') { echo "<h3>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "<font color='grey'>{$cat['name']}</font></h3>"; } else { echo "<h3>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "{$cat['name']}</h3>"; } foreach ($wn->getSubCategories($cat['cid']) as $key => $subcat) { if ($subcat['childcats'] > 0) { echo '<div data-role="collapsibleset" data-theme="<?=$theme;?>" data-content-theme="<?=$content_theme;?>" data-inset="false" data-corners="false" style="padding:0px;margin-top:-10px;">'; echo '<div data-role="collapsible" data-collapsed-icon="carat-d" data-expanded-icon="carat-d" data-iconpos="right" data-inset="false">'; if ($subcat['status'] == '2') { echo "<h1 style='color:grey;'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], "W_TAG-SUBCAT") . "{$subcat['name']}</h1>"; } else { echo "<h1><a style='text-decoration:inherit;color:inherit;' href='#" . $subcat['scid'] . "'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], "W_TAG-SUBCAT") . "{$subcat['name']}</a></h1>"; } echo "<ul data-role='listview'>"; foreach ($wn->getChildCategories($cat['cid'], $subcat['scid']) as $key => $childcat) { if ($childcat['status'] == '2') { echo "<li style='color:grey;'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], $childcat['ccid'], "W_TAG-CHILDCAT") . "{$childcat['name']}</li>"; } else { echo "<li><a href='products.php?cid=" . $cat['cid'] . "&scid=" . $subcat['scid'] . "&ccid=" . $childcat['ccid'] . "'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], $childcat['ccid'], "W_TAG-CHILDCAT") . "{$childcat['name']}</a></li>"; } } echo "</ul>"; echo "</div></div>"; } else { echo "<ul data-role='listview'>"; if ($subcat['status'] == '2') { echo "<li style='color:grey;'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], "W_TAG-SUBCAT") . "{$subcat['name']}</li>"; } else { echo "<li style='margin:-8px;margin-top:-5px;padding-right:8px;padding-top:0px;padding-bottom:4px;'><a href='products.php?cid=" . $cat['cid'] . "&scid=" . $subcat['scid'] . "'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], "W_TAG-SUBCAT") . "{$subcat['name']}</a></li>"; } echo "</ul>"; } } echo "</div>"; } else { echo '<div data-role="collapsible" data-corners="false" data-inset="false" data-collapsed-icon="carat-d" data-expanded-icon="carat-d" data-iconpos="right" id="' . $cat['id'] . '">'; if ($cat['status'] == '2') { echo "<h3>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "<font color='grey'>{$cat['name']}</font></h3>"; } else { echo "<h3>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "{$cat['name']}</h3>"; } echo "<ul data-role='listview'>"; foreach ($wn->getSubCategories($cat['cid']) as $key => $subcat) { if ($subcat['status'] == '2') { echo "<li>" . $wn->getItemIcon($cat['cid'], $subcat['scid']) . "{$subcat['name']}</li>"; } else { echo "<li><a href='products.php?cid=" . $cat['cid'] . "&scid=" . $subcat['scid'] . "'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], "W_TAG-SUBCAT") . "{$subcat['name']}</a></li>"; } } echo "</ul> </div>"; } } else { echo "<ul data-role='listview'>"; if ($cat['status'] == '2') { echo "<li style='color:grey;'>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "{$cat['name']}</li>"; } else { echo "<li><a href='products.php?cid=" . $cat['cid'] . "'>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "{$cat['name']}</a></li>"; } echo "</ul>"; } } ?> WhatsNew.base.php <?php function getCatType(){ $args=func_get_args(); $cid=$args[0]; $scid=$args[1]; $ccid=$args[2]; $ccid=$args[3]; $ret=array(); if(empty($cid) && empty($ccid) && empty($scid) || !is_numeric($cid) && !is_numeric($ccid) && !is_numeric($scid)){ $ret['query_name']="Categories"; $ret['query_table']="categories"; } elseif((!empty($cid) && is_numeric($cid)) && (empty($ccid) && empty($scid) || !is_numeric($ccid) && !is_numeric($scid))){ $ret['query_name']="Categories"; $ret['query_table']="categories"; $ret['query_table_condition']="cid='$cid'"; } elseif((!empty($cid) && !empty($scid) && is_numeric($cid) && is_numeric($scid)) && (empty($ccid) && !is_numeric($ccid))){ $ret['name']="Categories"; $ret['table']="Categories"; $ret['query_name']="Sub-categories"; $ret['query_table']="subcategories"; $ret['query_table_condition']="cid='$cid' AND scid='$scid'"; } elseif(!empty($cid) && !empty($scid) && !empty($ccid) && is_numeric($cid) && is_numeric($scid) && is_numeric($ccid)){ $ret['name']="Sub-categories"; $ret['table']="subcategories"; $ret['query_name']="Child-categories"; $ret['query_table']="childcategories"; $ret['query_table_condition']="cid='$cid' AND scid='$scid' AND ccid='$ccid'"; } elseif(!empty($cid) && !empty($scid) && !empty($ccid) && !empty($pid) && is_numeric($cid) && is_numeric($scid) && is_numeric($ccid) && is_numeric($pid)){ $ret['name']="Child-categories"; $ret['table']="childcategories"; $ret['query_name']="Products"; $ret['query_table']="products"; $ret['query_table_condition']="cid='$cid' AND scid='$scid' AND ccid='$ccid' AND pid='$pid'"; } return $ret; } function getOidParams($param=array()){ $return=array(); foreach($param as $key){ if(is_numeric($key)){ if(strlen($key)==10){ $return['cid']=$key; } if(strlen($key)==8){ $return['scid']=$key; } if(strlen($key)==6){ $return['ccid']=$key; } if(strlen($key)==4){ $return['pid']=$key; } } } return $return; } function isIconHidden(){ $args=func_get_args(); $cid=$args[0]; $scid=$args[1]; $ccid=$args[2]; if($q=db_query("SELECT showicon FROM $this->getCatType($cid,$scid,$ccid)['table'] WHERE $this->getCatType($cid,$scid,$ccid)['query_table_condition']",$this->db)){ if(db_num_rows($q)>0){ $r=db_fetch_array($q); return $r['showicon']; } } } function getItemIcon(){ $args=func_get_args(); $param=array($args[0],$args[1],$args[2],$args[3]); $tbl=$this->getCatType($this->getOidParams($param)['cid'],$this->getOidParams($param)['scid'],$this->getOidParams($param)['ccid'],$this->getOidParams($param)['pid'])['query_table']; $tbl_cond=$this->getCatType($this->getOidParams($param)['cid'],$this->getOidParams($param)['scid'],$this->getOidParams($param)['ccid'],$this->getOidParams($param)['pid'])['query_table_condition']; if($q=db_query("SELECT icon,icon_mime FROM $tbl WHERE $tbl_cond",$this->db)){ if(db_num_rows($q)>0){ $r=db_fetch_array($q); if($r['showicon']==0){ return ""; } elseif($r['showicon']==1){ if(in_array("W_TAG-MAINCAT",$param)){ $ret="<div style='float:left;;'><img src='".bin2file($r['icon'],$r['icon_mime'])."' width='24' height='24'/></div>"; } elseif(in_array("W_TAG-SUBCAT",$param)){ $ret="<div style='float:left;'><img src='".bin2file($r['icon'],$r['icon_mime'])."' width='24' height='24'/></div>"; } elseif(in_array("W_TAG-CHILDCAT",$param)){ $ret="<div style='float:left;margin-left:10px;'><img src='".bin2file($r['icon'],$r['icon_mime'])."' width='24' height='24'/></div>"; } elseif(in_array("W_TAG-PRODUCTCAT",$param)){ $ret="<div style='float:left;margin-left:15px;'><img src='".bin2file($r['icon'],$r['icon_mime'])."' width='24' height='24'/></div>"; } else { $ret=bin2file($r['icon'],$r['icon_mime']); } return $ret; } } } else { echo error("Unable to query database! {$this->hcMsg}"); } } function getSubCategoriesCount($cid){ $sccq=db_query("SELECT scid FROM subcategories WHERE cid='$cid' AND status != '1' ORDER BY name ASC",$this->db); if($sccq){ if(db_num_rows($sccq)>0){ $sccr=db_fetch_array($sccq); $result=array("subcategories"=>array("scid"=>$sccr['scid'],"count"=>db_num_rows($sccq))); } else { $result=array("scid"=>"NULL","count"=>"0"); } return $result; } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getSubCategoryCounts() function getChildCategoriesCount($cid,$scid){ $cccq=db_query("SELECT ccid FROM childcategories WHERE cid='$cid' AND scid='$scid' AND status != '1' ORDER BY name ASC",$this->db); $result=array(); if($cccq){ if(db_num_rows($cccq)>0){ $cccr=db_fetch_array($sccq); $result=array("childcategories"=>array("ccid"=>$cccr['ccid'],"count"=>db_num_rows($cccq))); } else { $result=array("ccid"=>"NULL","count"=>"0"); } return $result; } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getChildCategoryCounts() function getProductsCount(){ $args=func_get_args(); $cid=$args[0]; $scid=$args[1]; $ccid=$args[2]; if(!empty($cid) && !empty($scid) && !empty($ccid) && is_numeric($cid) && is_numeric($scid) && is_numeric($ccid)){ $pcq=db_query("SELECT pid FROM products WHERE cid='$cid' AND scid='$scid' AND ccid='$scid' AND status != '1' ORDER BY name ASC",$this->db); } elseif((!empty($cid) && !empty($scid) && is_numeric($cid) && is_numeric($scid)) && (empty($ccid) && !is_numeric($ccid))){ $pcq=db_query("SELECT pid FROM products WHERE cid='$cid' AND scid='$scid' AND ccid='' AND status != '1' ORDER BY name ASC",$this->db); } elseif((!empty($cid) && is_numeric($cid)) && (empty($ccid) && empty($scid) || !is_numeric($ccid) && !is_numeric($scid))){ $pcq=db_query("SELECT pid FROM products WHERE cid='$cid' AND scid='' AND ccid='' AND status != '1' ORDER BY name ASC",$this->db); } if($pcq){ if(db_num_rows($pcq)>0){ return db_num_rows($pcq); } else { echo error("No products found in any categories!"); } } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getProductsCount() function getCategories(){ $cq1=db_query("SELECT * FROM categories WHERE status != '1' ORDER BY name ASC",$this->db); if($cq1){ if(db_num_rows($cq1)>0){ $result=array(); while($cr1=db_fetch_array($cq1)){ foreach($cr1 as $key => $subArr){ unset($cr1['icon']); unset($cr1['icon_mime']); unset($cr1[2]); unset($cr1[3]); } $cr1["subcats"]=$this->getSubCategoriesCount($cr1['cid'])['count']; $cr1["childcats"]=$this->getChildCategoriesCount($cr1['cid'],$this->getSubCategoriesCount($cr1['cid'])['scid'])['count']; array_push($result,$cr1); } return $result; } else { echo error("No categories found!"); } } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getCategories() function getSubCategories($cid){ $scq1=db_query("SELECT * FROM subcategories WHERE cid='$cid' AND status != '1' ORDER BY name ASC",$this->db); if($scq1){ if(db_num_rows($scq1)>0){ $result = array(); while($scr1=db_fetch_array($scq1)){ foreach($scr1 as $key => $subArr){ unset($scr1['icon']); unset($scr1['icon_mime']); unset($scr1[2]); unset($scr1[3]); } if($ccq=db_query("SELECT ccid FROM childcategories WHERE cid='$cid' AND scid='".$scr1['scid']."' AND status != '1' ORDER BY name ASC",$this->db)){ if(db_num_rows($ccq)>0){ while($ccr=db_fetch_array($ccq)){ $scr1["childcats"]=db_num_rows($ccq); } } else { $scr1["childcats"]="0"; } } else { $scr1["childcats"]="0"; } array_push($result,$scr1); } return $result; } else { echo error("No sub-categories found!"); } } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getSubCategories() function getChildCategories($cid,$scid){ $ccq1=db_query("SELECT * FROM childcategories WHERE cid='$cid' AND scid='$scid' AND status != '1' ORDER BY name ASC",$this->db); if($ccq1){ if(db_num_rows($ccq1)>0){ $result = array(); while($ccr1=db_fetch_array($ccq1)){ foreach($ccr1 as $key => $subArr){ unset($ccr1['icon']); unset($ccr1['icon_mime']); unset($ccr1[2]); unset($ccr1[3]); } array_push($result,$ccr1); } return $result; } else { echo error("No child-categories found!"); } } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getChildCategories() ?>
sagnik Posted July 17, 2017 Author Posted July 17, 2017 I've a problem with my code. I want to fetch rows from mysql by category. I've 3 tables (categories,subcategories & childcategories). If the code works properly, it will look like, categories=parent table, subcategories=children table of categories, childcategories=children of subcategories and sibling table of categoriescid,scid,ccid=unique numberscid=categories.cid (10digit), scid=subcategories.scid (8digit), ccid=childcategories.ccid (6digit) HOW IT WILL LOOK IN HTML OUTPUT: IF EVERY TABLE HAS CHILD ELEMENTS:- item-1 - item-1a - item-1a1 - item-1b - item-1b1 IF 1ST ROW IS A CHILD OF SUBCATEGORIES & 2ND ROW OF SUBCATEGORIES DOESN'T HAVE ANY CHILD ELEMENTS:- item-1 - item-1a - item-1a1 - item-1b IF 1ST ROW IS A CHILD OF CATEGORIES & 2ND ROW OF CATEGORIES DOESN'T HAVE ANY CHILD ELEMENTS:- item-1 - item-1a- item-2 IF ANY OF CATEGORIES DOESN'T HAVE ANY CHILD ELEMENTS:- item-1- item-2 HOW IT LOOKS IN PHPMYADMIN:table:categories table:subcategoriestable:childcategories HERE IS THE CODES:panels.php <?php $db2 = $wnd->getDatabase("listings"); $wn = new WhatsNew($db2); foreach ($wn->getCategories() as $key => $cat) { if ($cat['subcats'] > 0) { if ($cat['childcats'] > 0) { echo '<div data-role="collapsible" data-inset="false" data-collapsed-icon="plus" data-expanded-icon="minus" data-iconpos="right" id="' . $cat['id'] . '">'; if ($cat['status'] == '2') { echo "<h3>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "<font color='grey'>{$cat['name']}</font></h3>"; } else { echo "<h3>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "{$cat['name']}</h3>"; } foreach ($wn->getSubCategories($cat['cid']) as $key => $subcat) { if ($subcat['childcats'] > 0) { echo '<div data-role="collapsibleset" data-theme="<?=$theme;?>" data-content-theme="<?=$content_theme;?>" data-inset="false" data-corners="false" style="padding:0px;margin-top:-10px;">'; echo '<div data-role="collapsible" data-collapsed-icon="carat-d" data-expanded-icon="carat-d" data-iconpos="right" data-inset="false">'; if ($subcat['status'] == '2') { echo "<h1 style='color:grey;'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], "W_TAG-SUBCAT") . "{$subcat['name']}</h1>"; } else { echo "<h1><a style='text-decoration:inherit;color:inherit;' href='#" . $subcat['scid'] . "'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], "W_TAG-SUBCAT") . "{$subcat['name']}</a></h1>"; } echo "<ul data-role='listview'>"; foreach ($wn->getChildCategories($cat['cid'], $subcat['scid']) as $key => $childcat) { if ($childcat['status'] == '2') { echo "<li style='color:grey;'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], $childcat['ccid'], "W_TAG-CHILDCAT") . "{$childcat['name']}</li>"; } else { echo "<li><a href='products.php?cid=" . $cat['cid'] . "&scid=" . $subcat['scid'] . "&ccid=" . $childcat['ccid'] . "'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], $childcat['ccid'], "W_TAG-CHILDCAT") . "{$childcat['name']}</a></li>"; } } echo "</ul>"; echo "</div></div>"; } else { echo "<ul data-role='listview'>"; if ($subcat['status'] == '2') { echo "<li style='color:grey;'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], "W_TAG-SUBCAT") . "{$subcat['name']}</li>"; } else { echo "<li style='margin:-8px;margin-top:-5px;padding-right:8px;padding-top:0px;padding-bottom:4px;'><a href='products.php?cid=" . $cat['cid'] . "&scid=" . $subcat['scid'] . "'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], "W_TAG-SUBCAT") . "{$subcat['name']}</a></li>"; } echo "</ul>"; } } echo "</div>"; } else { echo '<div data-role="collapsible" data-corners="false" data-inset="false" data-collapsed-icon="carat-d" data-expanded-icon="carat-d" data-iconpos="right" id="' . $cat['id'] . '">'; if ($cat['status'] == '2') { echo "<h3>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "<font color='grey'>{$cat['name']}</font></h3>"; } else { echo "<h3>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "{$cat['name']}</h3>"; } echo "<ul data-role='listview'>"; foreach ($wn->getSubCategories($cat['cid']) as $key => $subcat) { if ($subcat['status'] == '2') { echo "<li>" . $wn->getItemIcon($cat['cid'], $subcat['scid']) . "{$subcat['name']}</li>"; } else { echo "<li><a href='products.php?cid=" . $cat['cid'] . "&scid=" . $subcat['scid'] . "'>" . $wn->getItemIcon($cat['cid'], $subcat['scid'], "W_TAG-SUBCAT") . "{$subcat['name']}</a></li>"; } } echo "</ul> </div>"; } } else { echo "<ul data-role='listview'>"; if ($cat['status'] == '2') { echo "<li style='color:grey;'>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "{$cat['name']}</li>"; } else { echo "<li><a href='products.php?cid=" . $cat['cid'] . "'>" . $wn->getItemIcon($cat['cid'], "W_TAG-MAINCAT") . "{$cat['name']}</a></li>"; } echo "</ul>"; } } ?> WhatsNew.base.php <?php function getCatType(){ $args=func_get_args(); $cid=$args[0]; $scid=$args[1]; $ccid=$args[2]; $ccid=$args[3]; $ret=array(); if(empty($cid) && empty($ccid) && empty($scid) || !is_numeric($cid) && !is_numeric($ccid) && !is_numeric($scid)){ $ret['query_name']="Categories"; $ret['query_table']="categories"; } elseif((!empty($cid) && is_numeric($cid)) && (empty($ccid) && empty($scid) || !is_numeric($ccid) && !is_numeric($scid))){ $ret['query_name']="Categories"; $ret['query_table']="categories"; $ret['query_table_condition']="cid='$cid'"; } elseif((!empty($cid) && !empty($scid) && is_numeric($cid) && is_numeric($scid)) && (empty($ccid) && !is_numeric($ccid))){ $ret['name']="Categories"; $ret['table']="Categories"; $ret['query_name']="Sub-categories"; $ret['query_table']="subcategories"; $ret['query_table_condition']="cid='$cid' AND scid='$scid'"; } elseif(!empty($cid) && !empty($scid) && !empty($ccid) && is_numeric($cid) && is_numeric($scid) && is_numeric($ccid)){ $ret['name']="Sub-categories"; $ret['table']="subcategories"; $ret['query_name']="Child-categories"; $ret['query_table']="childcategories"; $ret['query_table_condition']="cid='$cid' AND scid='$scid' AND ccid='$ccid'"; } elseif(!empty($cid) && !empty($scid) && !empty($ccid) && !empty($pid) && is_numeric($cid) && is_numeric($scid) && is_numeric($ccid) && is_numeric($pid)){ $ret['name']="Child-categories"; $ret['table']="childcategories"; $ret['query_name']="Products"; $ret['query_table']="products"; $ret['query_table_condition']="cid='$cid' AND scid='$scid' AND ccid='$ccid' AND pid='$pid'"; } return $ret; } function getOidParams($param=array()){ $return=array(); foreach($param as $key){ if(is_numeric($key)){ if(strlen($key)==10){ $return['cid']=$key; } if(strlen($key)==8){ $return['scid']=$key; } if(strlen($key)==6){ $return['ccid']=$key; } if(strlen($key)==4){ $return['pid']=$key; } } } return $return; } function isIconHidden(){ $args=func_get_args(); $cid=$args[0]; $scid=$args[1]; $ccid=$args[2]; if($q=db_query("SELECT showicon FROM $this->getCatType($cid,$scid,$ccid)['table'] WHERE $this->getCatType($cid,$scid,$ccid)['query_table_condition']",$this->db)){ if(db_num_rows($q)>0){ $r=db_fetch_array($q); return $r['showicon']; } } } function getItemIcon(){ $args=func_get_args(); $param=array($args[0],$args[1],$args[2],$args[3]); $tbl=$this->getCatType($this->getOidParams($param)['cid'],$this->getOidParams($param)['scid'],$this->getOidParams($param)['ccid'],$this->getOidParams($param)['pid'])['query_table']; $tbl_cond=$this->getCatType($this->getOidParams($param)['cid'],$this->getOidParams($param)['scid'],$this->getOidParams($param)['ccid'],$this->getOidParams($param)['pid'])['query_table_condition']; if($q=db_query("SELECT icon,icon_mime FROM $tbl WHERE $tbl_cond",$this->db)){ if(db_num_rows($q)>0){ $r=db_fetch_array($q); if($r['showicon']==0){ return ""; } elseif($r['showicon']==1){ if(in_array("W_TAG-MAINCAT",$param)){ $ret="<div style='float:left;;'><img src='".bin2file($r['icon'],$r['icon_mime'])."' width='24' height='24'/></div>"; } elseif(in_array("W_TAG-SUBCAT",$param)){ $ret="<div style='float:left;'><img src='".bin2file($r['icon'],$r['icon_mime'])."' width='24' height='24'/></div>"; } elseif(in_array("W_TAG-CHILDCAT",$param)){ $ret="<div style='float:left;margin-left:10px;'><img src='".bin2file($r['icon'],$r['icon_mime'])."' width='24' height='24'/></div>"; } elseif(in_array("W_TAG-PRODUCTCAT",$param)){ $ret="<div style='float:left;margin-left:15px;'><img src='".bin2file($r['icon'],$r['icon_mime'])."' width='24' height='24'/></div>"; } else { $ret=bin2file($r['icon'],$r['icon_mime']); } return $ret; } } } else { echo error("Unable to query database! {$this->hcMsg}"); } } function getSubCategoriesCount($cid){ $sccq=db_query("SELECT scid FROM subcategories WHERE cid='$cid' AND status != '1' ORDER BY name ASC",$this->db); if($sccq){ if(db_num_rows($sccq)>0){ $sccr=db_fetch_array($sccq); $result=array("subcategories"=>array("scid"=>$sccr['scid'],"count"=>db_num_rows($sccq))); } else { $result=array("scid"=>"NULL","count"=>"0"); } return $result; } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getSubCategoryCounts() function getChildCategoriesCount($cid,$scid){ $cccq=db_query("SELECT ccid FROM childcategories WHERE cid='$cid' AND scid='$scid' AND status != '1' ORDER BY name ASC",$this->db); $result=array(); if($cccq){ if(db_num_rows($cccq)>0){ $cccr=db_fetch_array($sccq); $result=array("childcategories"=>array("ccid"=>$cccr['ccid'],"count"=>db_num_rows($cccq))); } else { $result=array("ccid"=>"NULL","count"=>"0"); } return $result; } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getChildCategoryCounts() function getProductsCount(){ $args=func_get_args(); $cid=$args[0]; $scid=$args[1]; $ccid=$args[2]; if(!empty($cid) && !empty($scid) && !empty($ccid) && is_numeric($cid) && is_numeric($scid) && is_numeric($ccid)){ $pcq=db_query("SELECT pid FROM products WHERE cid='$cid' AND scid='$scid' AND ccid='$scid' AND status != '1' ORDER BY name ASC",$this->db); } elseif((!empty($cid) && !empty($scid) && is_numeric($cid) && is_numeric($scid)) && (empty($ccid) && !is_numeric($ccid))){ $pcq=db_query("SELECT pid FROM products WHERE cid='$cid' AND scid='$scid' AND ccid='' AND status != '1' ORDER BY name ASC",$this->db); } elseif((!empty($cid) && is_numeric($cid)) && (empty($ccid) && empty($scid) || !is_numeric($ccid) && !is_numeric($scid))){ $pcq=db_query("SELECT pid FROM products WHERE cid='$cid' AND scid='' AND ccid='' AND status != '1' ORDER BY name ASC",$this->db); } if($pcq){ if(db_num_rows($pcq)>0){ return db_num_rows($pcq); } else { echo error("No products found in any categories!"); } } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getProductsCount() function getCategories(){ $cq1=db_query("SELECT * FROM categories WHERE status != '1' ORDER BY name ASC",$this->db); if($cq1){ if(db_num_rows($cq1)>0){ $result=array(); while($cr1=db_fetch_array($cq1)){ foreach($cr1 as $key => $subArr){ unset($cr1['icon']); unset($cr1['icon_mime']); unset($cr1[2]); unset($cr1[3]); } $cr1["subcats"]=$this->getSubCategoriesCount($cr1['cid'])['count']; $cr1["childcats"]=$this->getChildCategoriesCount($cr1['cid'],$this->getSubCategoriesCount($cr1['cid'])['scid'])['count']; array_push($result,$cr1); } return $result; } else { echo error("No categories found!"); } } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getCategories() function getSubCategories($cid){ $scq1=db_query("SELECT * FROM subcategories WHERE cid='$cid' AND status != '1' ORDER BY name ASC",$this->db); if($scq1){ if(db_num_rows($scq1)>0){ $result = array(); while($scr1=db_fetch_array($scq1)){ foreach($scr1 as $key => $subArr){ unset($scr1['icon']); unset($scr1['icon_mime']); unset($scr1[2]); unset($scr1[3]); } if($ccq=db_query("SELECT ccid FROM childcategories WHERE cid='$cid' AND scid='".$scr1['scid']."' AND status != '1' ORDER BY name ASC",$this->db)){ if(db_num_rows($ccq)>0){ while($ccr=db_fetch_array($ccq)){ $scr1["childcats"]=db_num_rows($ccq); } } else { $scr1["childcats"]="0"; } } else { $scr1["childcats"]="0"; } array_push($result,$scr1); } return $result; } else { echo error("No sub-categories found!"); } } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getSubCategories() function getChildCategories($cid,$scid){ $ccq1=db_query("SELECT * FROM childcategories WHERE cid='$cid' AND scid='$scid' AND status != '1' ORDER BY name ASC",$this->db); if($ccq1){ if(db_num_rows($ccq1)>0){ $result = array(); while($ccr1=db_fetch_array($ccq1)){ foreach($ccr1 as $key => $subArr){ unset($ccr1['icon']); unset($ccr1['icon_mime']); unset($ccr1[2]); unset($ccr1[3]); } array_push($result,$ccr1); } return $result; } else { echo error("No child-categories found!"); } } else { echo error("Unable to query database! {$this->hcMsg}"); } } //END FUNCTION: getChildCategories() ?>
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now