News:

Looking for documentation? Take a look on our wiki

Main Menu

SQL Syntax help :)

Started by NikolaPGcity, January 30, 2013, 14:47:08 PM

Previous topic - Next topic

NikolaPGcity

Hello

can anybody help me with this thing in VM

current query is

$query = "SELECT COUNT(*) AS total FROM #__vm_product_category_xref WHERE category_id=" . $row->category_id;

and it takes all products from category.
But i need only products which are published, not inactive.

so i need

prodcut_publish = ' Y '



from table vm_product

Thanks

stinga

I would turn it off altogether if you can, uless you don't have too many product/categories.
but

$query = "SELECT COUNT(*) AS total FROM #__vm_product_category_xref vpcx, #__vm_product vp WHERE vpcx.product_id = vp.product_id and vpcx.category_id=" . $row->category_id;

Something like that.
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4

PRO

what are you trying to do?

just count the # of products in a category?

http://forum.virtuemart.net/index.php?topic=112519.0

NikolaPGcity

hi

thanks for your reposne
first this is mod_tpindexvm module.

here is code of helper file
<?php
defined('_JEXEC') or die('Restricted access');
class modTPIndexHelper{

function getList(&$params){
global $mainframe;

$img = ($params->get('modtype') == 0)  ? "category_full_image" "category_thumb_image";
$db =& JFactory::getDBO();
$query "SELECT b.category_name, b.category_description, b.category_id, b." $img " FROM #__vm_category_xref AS a, #__vm_category AS b WHERE a.category_parent_id = 0 AND a.category_child_id = b.category_id AND b.category_publish = 'Y' ORDER BY b.category_id ASC";
$db->setQuery($query);
$rows $db->loadObjectList();

$i 0;
$lists = array();
foreach($rows as $row){
$lists[$i]->name $row->category_name;
$lists[$i]->desc $row->category_description;
$lists[$i]->id $row->category_id;
$lists[$i]->filename$row->$img;
$i++;
}

return $lists;
}

function getListChild($params$param){
global $mainframe;

$img = ($params->get('modtype') == 0)  ? "category_full_image" "category_thumb_image";
$db =& JFactory::getDBO();
$query "SELECT b.category_name, b.category_id, b." $img " FROM #__vm_category_xref AS a, #__vm_category AS b WHERE a.category_parent_id = $param AND a.category_child_id = b.category_id AND b.category_publish = 'Y' ORDER BY b.category_id ASC";
$db->setQuery($query);
$rows $db->loadObjectList();

$i 0;
$lists = array();
foreach($rows as $row){
$query "SELECT COUNT(*) AS total FROM #__vm_product_category_xref WHERE category_id=" $row->category_id;
$db->setQuery($query);
$lists[$i]->name $row->category_name;
$lists[$i]->id $row->category_id;
$lists[$i]->filename$row->$img;
$lists[$i]->total $db->loadResult();
$i++;
}

return $lists;
}
}
?>


at line 43 there is line which count product's in category and in default at line 135 and 74 that show that count
<?php
defined('_JEXEC') or die('Restricted access');

$menu = &JSite::getMenu();
$items $menu->getItems('link''index.php?option=com_virtuemart');
$itemid = isset($items[0]) ? '&Itemid='.$items[0]->id '';

$modtype $params->get('modtype');
$showtitle $params->get('showtitle');
$showdesc $params->get('showdesc');
$showsubcat $params->get('showsubcat');
$showthumb $params->get('showthumb');
$col $params->get ('num_cols'2);
$colwidth floor(100/$col);
$x 0;
$y 1;
$row ceil(count($list)/$col);
$total $col*$row;
$rest = ($total-count($list))+1;
$max        2;

if($modtype == 0){
$headtag "<link rel=\"stylesheet\" href=\"" JURI::root() . "/modules/mod_tpindexvm/tmpl/tpindexvm.css\" type=\"text/css\" />";
}else{
$headtag "<link rel=\"stylesheet\" href=\"" JURI::root() . "/modules/mod_tpindexvm/tmpl/tpindexvm_menu.css\" type=\"text/css\" />";
}
$mainframe->addCustomHeadTag($headtag);

if($list){
if($modtype == 0){
$data  "<div class=\"productthumb\">";
$data .= '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
for($a=0$a<$total$a++){
if($y == 1){
$data .= '<tr valign="top"><td width="' $colwidth '%">';
}else{
$data .= '<td width="' $colwidth '%">';
}


if(isset($list[$a]->id)){
$linkp JRoute::_('index.php?option=com_virtuemart&page=shop.browse&category_id='.$list[$a]->id.$itemidfalse);
$data .= "<div class=\"pthumb\">";

if($showthumb == 1){
$class " bbb";
}else{
$class "";
}

if($showtitle == 1){
$data .= "<a href=\"$linkp\" title=\"" $list[$a]->name "\" id=\"productthumbbig$x\" class=\"productthumbbigtitle\">";
$data .= "<span>" $list[$a]->name "</span>";
$data .= "</a>";
}

if($showthumb == 1){
$data .= "<a href=\"$linkp\" title=\"" $list[$a]->name "\" id=\"productthumbbig$x\" class=\"productthumbbig\">";
$data .= "<div class=\"pthumbimg\"><img src='" JURI::base(true) . "/components/com_virtuemart/shop_image/category/" $list[$a]->filename "' /></div>";
$data .= "</a>";
}

if($showdesc == || $showsubcat == 1){
$data .= "<div class='detail" $class "'>";

if($showdesc == 1){ $data .= "<div class='desc'>" $list[$a]->desc "</div>";}

if($showsubcat == 1){
$child modTPIndexHelper::getListChild($params$list[$a]->id);
if(count($child) > 0){
$data .= "<ul>";
for($i=0$i<$max$i++){
$linkc JRoute::_('index.php?option=com_virtuemart&page=shop.browse&category_id='.$child[$i]->id.$itemidfalse);
$data .= "<li><a href=\"$linkc\" title=\"" $child[$i]->name "\">" $child[$i]->name " (" number_format($child[$i]->total0""".") . ")</a></li>";
}
if(count($child) > 0) {
$data .= "<li><a href=\"$linkp\"> Preostale kategorije </a></li>"; }
$data .= "</ul>";
}
}
$data .= "</div>";
$data .= "<div class='clear'></div>";
}
$data .= "</div>";
}else{
$data .= "&nbsp;";
}

$x++;
if($y == $col){
$data .= '</td></tr>';
$y 1;
}else{
$data .= '</td>';
$y++;
}
}
$data .= "</table>";
}else{
$data  "<div class=\"productthumb_menu\">";
$data .= '<ul class="parent">';
for($a=0$a<$total$a++){
if(isset($list[$a]->id)){
$data .= '<li>';
$linkp JRoute::_('index.php?option=com_virtuemart&page=shop.browse&category_id='.$list[$a]->id.$itemidfalse);
$data .= "<div class=\"pthumb\">";

if($showthumb == 1){
$class " bbb";
}else{
$class "";
}

$data .= "<a href=\"$linkp\" title=\"" $list[$a]->name "\" id=\"productthumbbig$x\" class=\"productthumbbigtitle\">";
$data .= "<span>" $list[$a]->name "</span>";
$data .= "</a>";

if($showthumb == 1){
$data .= "<a href=\"$linkp\" title=\"" $list[$a]->name "\" id=\"productthumbbig$x\" class=\"productthumbbig\">";
$data .= "<img src='" JURI::base(true) . "/components/com_virtuemart/shop_image/category/" $list[$a]->filename "' />";
$data .= "</a>";
}

if($showdesc == || $showsubcat == 1){
$data .= "<div class='detail" $class "'>";

if($showdesc == 1){ $data .= "<div class='desc'>" $list[$a]->desc "</div>";}

if($showsubcat == 1){
$child modTPIndexHelper::getListChild($params$list[$a]->id);
if(count($child) > 0){
$data .= "<ul>";
for($i=0$i<count($child); $i++){
$linkc JRoute::_('index.php?option=com_virtuemart&page=shop.browse&category_id='.$child[$i]->id.$itemidfalse);
$data .= "<li><a href=\"$linkc\" title=\"" $child[$i]->name "\">" $child[$i]->name " (" number_format($child[$i]->total0""".") . ")</a></li>";
}
$data .= "</ul>";
}
}
$data .= "</div>";
$data .= "<div class='clear'></div>";
}
$data .= "</div>";
$data .= '</li>';
}

$x++;
}
$data .= "</ul>";
}
$data .= "</div>";
}else{
$data "";
}
echo $data;
?>